Nginx 无法启动

Nginx 无法启动

我运行 Arch Linux,当我运行时:

sudo systemctl start nginx.service

我在日记中收到以下消息:

nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2019-05-15 11:17:03 BST; 45s ago
  Process: 1542 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; error_log stderr; (code=exited, status=1/FAILURE)

May 15 11:17:03 systemd[1]: Starting A high performance web server and a reverse proxy server...
May 15 11:17:03 nginx[1542]: 2019/05/15 11:17:03 [emerg] 1542#1542: a duplicate listen 0.0.0.0:80 in /etc/nginx/nginx.conf:42
May 15 11:17:03  systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
May 15 11:17:03  systemd[1]: nginx.service: Failed with result 'exit-code'.
May 15 11:17:03  systemd[1]: Failed to start A high performance web server and a reverse proxy server.

我不明白这里的错误。我该如何解决?

更新

● nginx.service - A high performance web server and a reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Wed 2019-05-15 11:36:36 BST; 9s ago
  Process: 1667 ExecStart=/usr/bin/nginx -g pid /run/nginx.pid; error_log stderr; (code=exited, status=1/FAILURE)

May 15 11:36:36  systemd[1]: Starting A high performance web server and a reverse proxy server...
May 15 11:36:36  nginx[1667]: 2019/05/15 11:36:36 [emerg] 1667#1667: getpwnam("www-data") failed in /etc/nginx/nginx.conf:3
May 15 11:36:36  systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE
May 15 11:36:36  systemd[1]: nginx.service: Failed with result 'exit-code'.
May 15 11:36:36  systemd[1]: Failed to start A high performance web server and a reverse proxy server.

答案1

还有其他东西监听端口 80,检查行:

duplicate listen 0.0.0.0:80

要查看哪个 PID 监听,您可以尝试

netstat -anp|grep :80

如果 nginx 配置有问题,你可以尝试这个最小的配置:

daemon            on;
worker_processes  2;
user              www-data;
events {
    use           epoll;
    worker_connections  128;
}
error_log         logs/error.log info;
http {
    server_tokens off;
    include       mime.types;
    charset       utf-8;
    access_log    logs/access.log  combined;
    server {
        server_name   localhost;
        listen        *:80;
        error_page    500 502 503 504  /50x.html;
        location      / {
            root      html;
        }
    }
}

相关内容