Home  >  Q&A  >  body text

centos7 - nginx configuration access_log problem

I want to enable access logs for nginx. Baidu took a look, mainly configuring

in nginx.conf

This section

#    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
#                      '$status $body_bytes_sent "$http_referer" '
#                      '"$http_user_agent" "$http_x_forwarded_for"';
#
#    access_log  logs/access.log  main;

is commented out with # by default. I want to turn it on, that is, uncomment this section with #.
Then restart nginx but it cannot be restarted, prompting
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.

It’s fine after adding # back. What’s the reason?
Including the error log at the beginning

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

I also removed the # to take effect, but nginx could not start.
`

为情所困为情所困2701 days ago814

reply all(1)I'll reply

  • 怪我咯

    怪我咯2017-05-27 17:46:58

    1. Please use nginx -t to check the configuration file to view the specific error information

    The log is processed like this

       log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                         '$status $body_bytes_sent "$http_referer" '
                         '"$http_user_agent" "$http_x_forwarded_for"';
    
       access_log  logs/access.log  main;

    reply
    0
  • Cancelreply