Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ RUN set -ex \
&& make \
&& make install \
&& ln -sf /etc/nginx/sbin/nginx /usr/local/bin/nginx \
&& mkdir -p /var/log/nginx \
&& ln -sf /dev/stdout /var/log/nginx/access.log \
&& ln -sf /dev/stderr /var/log/nginx/error.log
&& ln -sf /dev/stdout /etc/nginx/logs/access.log \
&& ln -sf /dev/stderr /etc/nginx/logs/error.log \
&& mkdir -p /tmp/polaris

CMD ["nginx", "-g", "daemon off;", "-c", "/etc/nginx/conf/nginx.conf"]
1 change: 1 addition & 0 deletions build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ folder_name=$(echo "nginx-gateway-release-${version}.${build_os}.${build_arch}"
echo "target name $folder_name"
rm -rf ../$folder_name
mkdir -p ../$folder_name
mkdir -p /tmp/polaris

pushd "$ngx_file_name"/
chmod +x configure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//

#include "ngx_http_polaris_limit_module.h"
#include "polaris/log.h"

typedef struct {
ngx_int_t enable; // 是否启用限流
Expand Down Expand Up @@ -420,8 +421,32 @@ const std::string defaultConfigContent = R"##(
service: polaris.limiter
)##";

const char kPathSeparator =
#ifdef _WIN32
'\\';
#else
'/';
#endif

std::string resolveNgxLogDir(ngx_log_t *logger) {
ngx_str_t* filename = &(logger->file->name);
std::string filename_str = std::string(reinterpret_cast<char *>(filename->data), filename->len);
int pos = filename_str.find_last_of(kPathSeparator);
if (pos == -1) {
return std::string("");
}
return filename_str.substr(0, pos);
}

void LimitApiWrapper::Init(ngx_log_t *logger) {
ngx_log_error(NGX_LOG_NOTICE, logger, 0, "[PolarisRateLimiting] start to init polaris limit api, polaris config %s", m_polaris_config.c_str());
std::string logDir = resolveNgxLogDir(logger);
if (logDir.size() == 0) {
logDir = DEFAULT_POLARIS_LOG_DIR;
}
ngx_log_error(NGX_LOG_NOTICE, logger, 0, "[PolarisRateLimiting] polaris logDir: %s", logDir.c_str());
polaris::SetLogDir(logDir);

std::string err_msg("");
m_limit = polaris::LimitApi::CreateFromString(m_polaris_config, err_msg);
if (NULL == m_limit) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static const std::string LABEL_KEY_HEADER = "$header.";
static const std::string LABEL_KEY_QUERY = "$query.";
static const std::string LABEL_KEY_CALLER_IP = "$caller_ip";
static const std::string PATH_SBIN = "sbin";
static const std::string DEFAULT_POLARIS_LOG_DIR = "/tmp/polaris";

class LimitApiWrapper {
public:
Expand Down
4 changes: 2 additions & 2 deletions third_party/nginx/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
error_log /var/log/nginx/error.log info;
error_log logs/error.log info;

#pid logs/nginx.pid;

Expand All @@ -22,7 +22,7 @@ http {
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;
access_log logs/access.log main;

sendfile on;
#tcp_nopush on;
Expand Down