无法将 http 请求路由到 Nginx 中的 Web 应用程序

无法将 http 请求路由到 Nginx 中的 Web 应用程序

我有一个在端口 5000 上运行的 reactjs 应用程序。我想将请求从 nginx 路由到 webapp。

我收到以下日志

2019/06/20 04:30:10 [error] 17709#17709: *67 connect() failed (111: Connection refused) while connecting to upstream, client: 72.163.217.106, server: 159.65.123.84, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8000/", host: “example.com”
2019/06/20 04:30:10 [error] 17709#17709: *69 connect() failed (111: Connection refused) while connecting to upstream, client: 72.163.217.106, server: 159.65.123.84, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: “example.com”, referrer: "http://example.com/“
2019/06/20 04:30:10 [error] 17709#17709: *71 connect() failed (111: Connection refused) while connecting to upstream, client: 72.163.217.106, server: 159.65.123.84, request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8000/favicon.ico", host: “example.com”, referrer: "http://example.com/“

这是我的 nginx 配置文件/etc/nginx/站点可用/默认

server {
    listen 0.0.0.0:80;
    server_name example.com; # or server_name subdomain.yourapp.com;

    location / {
        proxy_pass http://127.0.0.1:5000;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;

        # Enables WS support
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_redirect off;
    }
}

这种行为可能是什么原因造成的?如何解决这个问题。

答案1

似乎您正在将请求传递到 nginx 配置中的端口 8000。尝试将它们传递到端口 5000,因为根据您的帖子,您的 ReactJS 应用程序正在端口 5000 上运行。

相关内容