【问题标题】:Run nginx in static IP of server在服务器的静态 IP 中运行 nginx
【发布时间】:2020-02-09 11:06:29
【问题描述】:

对不起,我的英语不好,我无法很好地解释。

我有一个带有 Nginx 的 Windows Server 2012 的 VPS,并在端口 4000 上运行 Node 服务器,在端口 3000 上运行 React 客户端。

在远程桌面网站中运行在本地主机地址,但是当我在其他设备中使用服务器的静态 IP 时,我得到了来自服务器的任何响应。

无法访问此站点 XXX.XXX.192.176 响应时间过长。

我设置了IIS并连接到服务器,但是当IIS启动时,nginx无法启动。

nginx配置如下:

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;
    }
  }
}

【问题讨论】:

    标签: node.js reactjs nginx server windows-server-2012


    【解决方案1】:

    终于解决了问题:

    我只是将服务器的 IP 添加为 server_name 并检查了 windows 防火墙的端口 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;
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2020-05-18
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多