Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed

created at 07-15-2021 views: 70

description

Error prompt when start nginx

Starting nginx (via systemctl): nginx.serviceJob for nginx.service failed because the control process exited with error code.
 See "systemctl status nginx.service" and "journalctl -xe" for details.

cause of the problem

The configuration file is created under the directory system /etc/nginx/conf.d, the file name is: city.conf, the error prompted when using the /etc/init.d/nginx reload command

Configuration file content:

server {   
        listen 80;
        server_name 192.168.17.129 ;
        access_log  /var/log/nginx/access.log  main;
        charset  utf-8;
        gzip on;
        gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php application/json text/json image/jpeg image/gif image/png application/octet-stream;

        error_page  404           /404.html;
        error_page   500 502 503 504  /50x.html;

       # Specify the project path uwsgi
        location / {        
            include uwsgi_params; 
            uwsgi_connect_timeout 30;  
            uwsgi_pass unix:/home/script/uwsgi.sock;  # Specify that all dynamic requests for uwsgi's sock file will be directly thrown to it
        }

       # Specify the static file path
        location /static/ {
            alias  /home/trunk/static/;
            index  index.html index.htm;
        }

process

It is said on the Internet that this kind of error is generally because the directory does not exist or the authority is insufficient, so you can directly execute the following two commands, and it turns out that it does not work at all.

[root@typecodes ~]# cd /var/tmp/

[root@typecodes ~]# mkdir -p /var/tmp/nginx/{client,proxy,fastcgi,uwsgi,scgi}

final solution

1. Use the following command to get the error message as follows:

$ systemctl status nginx.service

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2017-08-22 04:12:48 PDT; 31min ago
  Process: 7030 ExecStop=/sbin/start-stop-daemon --quiet --stop --retry QUIT/5 --pidfile /run/nginx.pid (code=exited, status=0
  Process: 6525 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=1/FAILURE)
  Process: 6957 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
  Process: 7174 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=1/FAILURE)
 Main PID: 6961 (code=exited, status=0/SUCCESS)

Aug 22 04:12:48 ubuntu systemd[1]: Starting A high performance web server and a reverse proxy server...
Aug 22 04:12:48 ubuntu nginx[7174]: nginx: [emerg] unknown log format "main" in /etc/nginx/conf.d/city.conf:4Aug 22 04:12:48 ubuntu nginx[7174]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 22 04:12:48 ubuntu systemd[1]: nginx.service: Control process exited, code=exited status=1Aug 22 04:12:48 ubuntu systemd[1]: Failed to start A high performance web server and a reverse proxy server.
Aug 22 04:12:48 ubuntu systemd[1]: nginx.service: Unit entered failed state.
Aug 22 04:12:48 ubuntu systemd[1]: nginx.service: Failed with result 'exit-code'.
lines 1-16/16 (END)

2. According to the error message, it is found that there is a main error after access_log. Manually delete main in the configuration file to solve the problem

created at:07-15-2021
edited at: 07-15-2021: