使用Nginx无法访问在不同于80的端口上运行的server_block

时间:2019-07-30 10:46:41

标签: nginx server

我试图在公司服务器的80以外的端口上运行nginx。由于保留了80,因此我选择了8082端口。 我需要在没有域的情况下运行它,因此我只能使用IP地址和端口号来访问它。像这样的东西:serverip:8082

通过配置服务器块,我可以在自己的VPS上运行它。当我在公司服务器上尝试相同的设置时,它将无法正常工作。

server {
        listen 8082;
        listen [::]:8082;
        ...
}

更多信息

  • 服务器在Ubuntu 16.04上运行
  • 我没有在服务器块中使用server_name。
  • 服务器块已链接到/ etc / nginx / sites-enabled。
  • 我正在使用UFW,并且已启用8082(ufw是服务器上唯一启用的防火墙)
  • 我在nginx错误日志中没有看到错误。
  • 我尝试重新启动nginx
  • 我尝试编辑默认的server_block以监听端口8082。仍然没有。
  • 我尝试尝试自己取消链接默认的server_block。
  • 当我运行 sudo lsof -i TCP:8082 时,会得到如下结果:
COMMAND   PID     USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
nginx   19668     root    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19668     root    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19771 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19771 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19772 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19772 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19773 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19773 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19774 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19774 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19775 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19775 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19776 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19776 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19777 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19777 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
nginx   19778 www-data    6u  IPv4 20068810      0t0  TCP *:8082 (LISTEN)
nginx   19778 www-data    7u  IPv6 20068811      0t0  TCP *:8082 (LISTEN)
  • 我的整个server_block
server {
        listen 8082;
        listen [::]:8082;
        index index.php;
        client_max_body_size 50M;
        error_log /home/myuser/projects/synt_logs/synt.log;
        access_log /home/myuser/projects/synt_logs/synt.access.log;
        root /home/myuser/projects/synt/public;

        location /{
                try_files $uri $uri/ /index.php$query_string;
        }

        location ~ \.php {
                try_files $uri =404;
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                include fastcgi_params;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_param SCRIPT_NAME $fastcgi_script_name;
 fastcgi_index index.php;
                fastcgi_pass unix:/run/php/php7.2-fpm.sock;
        }
}


当我尝试连接到serverip:8082时,它会加载ERR_CONNECTION_TIMEOUT。

您能帮助我确定我面临的问题吗?从昨天开始,我一直试图解决这个问题,但没有成功。谢谢!

1 个答案:

答案 0 :(得分:0)

好的,所以问题在于VPS之外还有另一层防火墙阻止了端口8082。 通过与管理员联系,他为我解决了该问题,现在该问题已解决。

相关问题