首页 > 解决方案 > Node.js 应用程序使用服务器 IP 但不使用域名

问题描述

Node.js 应用程序在端口 80 上运行良好(使用 PM2 和 Nginx)并且可以很好地浏览服务器 IP。但是通过域它不起作用[无法访问此站点]。在 ping 域时可以看到响应中的服务器 IP。

这是我使用的 Nginx 配置:

location / {
    proxy_pass "http://127.0.0.1:8000";
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
    proxy_set_header Host $host;
    proxy_cache_bypass $http_upgrade;

}

标签: nginx

解决方案


您需要server_name在 Nginx 配置中使用声明。

server_name  example.org  www.example.org;

http://nginx.org/en/docs/http/server_names.html


推荐阅读