我获得了域nginx
的{{1}}配置文件,该文件将访问日志写入文件domainName.com
/var/log/nginx/logName.access.log
是否可以更改此配置文件,让nginx使用http状态代码server {
listen 80;
server_name domainName.com;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/rss+xml text/javascript image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype;
access_log /var/log/nginx/logName.access.log;
location / {
proxy_pass http://127.0.0.1:9000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~ ^/(min/|images/|ckeditor/|img/|javascripts/|apple-touch-icon-ipad.png|apple-touch-icon-ipad3.png|apple-touch-icon-iphone.png|apple-touch-icon-iphone4.png|generated/|js/|css/|stylesheets/|robots.txt|humans.txt|favicon.ico) {
root /root/Dropbox/nodeApps/nodeJsProject/port/public;
access_log off;
expires max;
}
}
或504
写入错误请求以分隔名为502
的文件
/var/log/nginx/bad.access.log
答案 0 :(得分:2)
如果您不介意为此错误创建自定义错误页面,则可能会这样做。
server {
...
access_log /var/log/nginx/logName.access.log;
location / {
proxy_pass http://127.0.0.1:9000/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
error_page 502 504 /50x.html;
}
...
location = /50x.html {
internal;
root /root/Dropbox/nodeApps/nodeJsProject/port/public;
access_log /var/log/nginx/bad.access.log;
}
}
您需要拥有文件/root/Dropbox/nodeApps/nodeJsProject/port/public/50x.html
。