我收到错误
/etc/nginx/conf.d/default.conf 中不允许使用“log_format”指令
nginx.conf
server {
---
--
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log custom if=$logme;
}
缺少什么?
了解
Context: http
文档的含义
events {
# ...
}
http {
upstream name {
# ...
}
# HERE
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
# ...
}
}
您应该在
http
下指定 server
,这样它看起来应该像:
server {
http {
# your server configurations
}
# The rest configurations
log_format custom '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log custom if=$logme;
}