我正在一个数字海洋滴运行nodejs应用程序,我正在尝试configurationnginx,以便它代理我的应用程序正在运行的端口端口,
这是我在我的站点上的默认文件可用
server { listen 80 default_server; listen [::]:80 default_server ipv6only=on; root /prwrite; index index.html index.htm app.js; # Make site accessible from http://localhost/ server_name http://www.xxx.xxxxx.com; location / { proxy_pass http://www.xxx.xxxx.com:3000/; proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } # Only for nginx-naxsi used with nginx-naxsi-ui : process denied requests #location /RequestDenied { # proxy_pass http://127.0.0.1:8080; #} error_page 404 /404.html;
}
在更改listen 80 default_server; 到3000,我的节点应用程序根本无法启动
但使用给定的configuration,如果我去http://XXX.XXXXXX.com:3000应用程序工作正常
并加载http://xxx.xxxxxxx.com
给了我很多404在我的页面上没有find错误
我怎样才能解决这个问题 ?
当node.js和nginx被告知使用端口3000时,你的应用程序无法启动,因为只有一个应用程序可以绑定到端口(考虑到它们都试图绑定到INADDR_ANY,即0.0.0.0)。
您可以通过在nginx config中添加代理位置来解决这种情况,比如location /socket.io/ { (或者更适合您的设置的东西),指向使用proxy_pass在端口3000上运行的location /socket.io/ {