欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Nginx 启用访问日志

最编程 2024-06-03 13:49:29
...

1. vi /etc/nginx/nginx.conf

2.打开 log_format 前的注释

3.Server节点中加入

access_log  logs/www_access.log  main;

server {
        listen       80;
        server_name  localhost;

log_format main '$remote_addr - $remote_user [$time_local] "$request" '
            '$status $body_bytes_sent "$http_referer" '
            '"$http_user_agent" "$http_x_forwarded_for"';


        location / {
            #root   html;
            #index  index.html index.htm;
        }
        access_log  logs/www_access.log  main;
}

4.重启Nginx,会报错,是因为没有创建日文件所在目录,建个目录就可以了

mkdir  -p /usr/share/nginx/logs/

 

Enjoy :)...