更改端口后 nginx 未重新启动

更改端口后 nginx 未重新启动

我尝试将 nginx 侦听的端口从 80 更改为 6000。但是,当我尝试重新启动它时,我得到了这个。

Restarting nginx: nginx: [emerg] bind() to 0.0.0.0:6000 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:6000 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:6000 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:6000 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:6000 failed (98: Address already in use)
nginx: [emerg] still could not bind()

这是我的启用站点的设置。

server {
    listen   6000; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default_server ipv6only=on; ## listen for ipv6

    root /var/www/mywebsite.co/html;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name mywebsite.co www.website.co;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ /index.html;
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

    location /doc/ {
            alias /usr/share/doc/;
            autoindex on;
            allow 127.0.0.1;
            allow ::1;
            deny all;
    }
}

我有一种感觉,应该0.0.0.0:6000是服务器所在的 IP 地址,192.168.1.3:6000但我不知道如何做到这一点。任何帮助将不胜感激。

答案1

尝试改变#listen [::]:80 default_server ipv6only=on; ## listen for ipv6

到: listen [::]:6000 ipv6only=on default_server;

如果这不起作用,您可以netstat -natp | grep 6000查看更多信息。

答案2

TCP 端口 6000 是 X Window 系统通常使用的端口。如果您使用的是非 Mac 的 UNIX 系统,并且您使用的是 GUI,则端口 6000 很可能已被本地计算机上运行的 X 服务器使用。这就是 nginx 无法绑定到它的原因。

答案3

要找出在众所周知的端口(即 tcp/6000)上运行的内容,您可以以 root 身份执行以下操作:

for i in $(grep [WELLKNOWNPORT] /etc/services|awk '{print $1}');执行 lsof|grep $i;完毕

相关内容