大网数据广告活动
服务器运维问答

Run nginx in static IP of server

· 52CE 我爱测

Sorry for my bad English, I can't explain it well. I have a VPS with Windows Server 2012 with Nginx and run a Node server at port 4000 and React client at port 3000. In remote desktop website run at localhost address but when I u…

问题原文

原帖链接 · Nima Kaviyani · CC BY-SA 4.0

Sorry for my bad English, I can't explain it well.

I have a VPS with Windows Server 2012 with Nginx and run a Node server at port 4000 and React client at port 3000.

In remote desktop website run at localhost address but when I use static IP of server in other device, I get any response from server.

This site can’t be reached XXX.XXX.192.176 took too long to respond.

I setup IIS and connected to the server, but when IIS is started, nginx can't start.

nginx is configured as follows:

worker_processes  1;

events {
  worker_connections  1024;
}


http {
  include       mime.types;
  default_type  application/octet-stream;

  sendfile        on;

  keepalive_timeout  65;

  server {
    listen 80;
    server_name  _;

    location /api {
        proxy_pass http://localhost:4000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "Upgrade";
    }
    location /socket.io {
            proxy_pass http://localhost:4000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
    }
    location / {
            proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   html;
    }
  }
}

已采纳解答

原帖链接 · Nima Kaviyani · CC BY-SA 4.0

Finally I solved the problem:

I just add IP of server as server_name and checked the windows firewall for port 80.

server {
    listen 80;
    server_name  XXX.XXX.192.176; // IP of server

    location /api {
        proxy_pass http://localhost:4000;
    }
    location /socket.io {
            proxy_pass http://localhost:4000;
    }
    location / {
            proxy_pass http://localhost:3000;
    }

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
      root   html;
    }
  }

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2020-02-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。