max*_*022 6 nginx amazon-web-services
我在 AWS 中有一个多容器设置。我正在尝试遵循此操作: http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/health-enhanced-serverlogs.html
但是(使用最新的 Nginx - 1.9.12),一旦我尝试在文件名中使用变量,我就会开始在错误日志中看到错误,并且文件本身不会创建。
错误日志:
2016/03/10 05:57:38 [error] 6#6: *1 testing "/etc/nginx/html" existence failed (2: No such file or directory) while logging request, client: xxx.xxx.xxx.xxx, server: localhost, request: "GET /v1/service?staus=ok HTTP/1.1", upstream: "http://xxx.xxx.xxx.xxx:8088/v1/service?staus=ok", host: "xxx.xxx.xxx.xxx"
Run Code Online (Sandbox Code Playgroud)
此配置不起作用:
upstream app_v1 {
server app_v1:8088;
}
map $http_upgrade $connection_upgrade {
default "upgrade";
"" "";
}
log_format healthd '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
server {
listen 80;
server_name localhost;
gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
set $hour $4;
}
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
location ~* ^/ {
proxy_pass http://app_v1;
proxy_redirect off;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Run Code Online (Sandbox Code Playgroud)
这个工作正常:
upstream app_v1 {
server app_v1:8088;
}
map $http_upgrade $connection_upgrade {
default "upgrade";
"" "";
}
log_format healthd '$msec"$uri"'
'$status"$request_time"$upstream_response_time"'
'$http_x_forwarded_for';
server {
listen 80;
server_name localhost;
gzip on;
gzip_comp_level 4;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
access_log /var/log/nginx/access.log main;
access_log /var/log/nginx/healthd/application.log healthd;
location ~* ^/ {
proxy_pass http://app_v1;
proxy_redirect off;
proxy_set_header Connection $connection_upgrade;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
Run Code Online (Sandbox Code Playgroud)
然而,healthd 服务(增强健康)正在寻找格式如下的文件:
/var/log/nginx/healthd/application.log.$year-$month-$day-$hour
Run Code Online (Sandbox Code Playgroud)
我可以使用 docker-compose 在本地重现此内容。我不确定我在这里缺少什么。
马克西姆
这是一个常见的陷阱。医生access_log
说:
\n\n\n文件路径可以包含变量(0.7.6+),但此类日志有一些限制:
\n\n\n
\n- ...
\n- 在每次日志写入期间,都会检查 request\xe2\x80\x99s根目录是否存在,如果不存在,则不会创建日志。
\n
您没有设置根目录,因此 nginx 会退回到默认目录,/etc/nginx/html
并且该目录不存在。
只需添加root /var/www;
(或其他一些现有路径),或者按照 zezollo 的建议,创建/etc/nginx/html
.
归档时间: |
|
查看次数: |
4260 次 |
最近记录: |