如何使用Nginx配置Express

时间:2019-02-20 06:56:06

标签: express nginx

根据this的文章,我已经用Express配置了Nginx。

这是我的Nginx配置:

server {
    access_log /var/log/nginx/access.log upstream_time;

    listen 8080;
    server_name _;

    location / {
        # default port, could be changed if you use next with custom server
        proxy_pass http://localhost:4000;

        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发送到Node应用程序的第一个请求是可以的,但是之后,任何请求都需要60秒才能响应。这是日志:

192.168.13.27 - - [20/Feb/2019:09:16:01 +0100] "GET / HTTP/1.1" 200 302276 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"rt=0.324 uct="0.000" uht="0.002" urt="0.002"
192.168.13.27 - - [20/Feb/2019:09:17:04 +0100] "GET / HTTP/1.1" 304 0 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36"rt=60.003 uct="0.000, 0.000" uht="60.002, 0.001" urt="60.002, 0.001"

如果我直接向端口4000上的节点应用发出请求,一切正常。

我已经搜索了StackOverflow以进一步查找,但问题仍然存在。我试图降低proxy_read_timeoutproxy_connect_timeout的值,但它仅适用于Express static模块中指定的静态文件,其他Express路由则抛出504网关超时错误。如何找到并解决问题?

0 个答案:

没有答案