繁体   English   中英

Node + Nginx反向代理永远无法工作

[英]Node + Nginx reverse proxy never works

我花了很多时间来进行这项工作,以至于缩短了实际的开发时间。 我试图在我的网站example.comexample2.com上设置两个域,但是在浏览器中导航到该域最多只能得到502。

我从朋友那里得到的etc/nginx/nginx.conf

user root;
worker_processes 4;


events {
        worker_connections 768;
}

http {

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
        types_hash_max_size 2048;

        server_names_hash_bucket_size 64;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;


        gzip on;
        gzip_disable "msie6";

        include /etc/nginx/sites-enabled/*;
}

我也从朋友那里得到的etc/nginx/sites-available/sites

server {
    server_name example.com;
    # proxy pass to nodejs
    location / {
        proxy_pass    http://127.0.0.1:9001/;
    }
}
server {
    server_name example2.com;
    # proxy pass to nodejs
    location / {
        proxy_pass    http://127.0.0.1:8000/;
    }
}

我一直在圈子里工作,并尝试了许多不同的配置以致全部失败,这一特定配置导致两个站点的网关错误502。

我从来没有能够做到这一点,我也不知道为什么,第二只眼睛会很有帮助。

在您的nginx配置中,看起来没有什么错。 如果nginx尝试将连接转发到的节点服务器实际上没有在您在配置中指定的端口上侦听,您将获得502状态代码。

要验证它是否正确侦听,可以使用可以连接到端口的任何工具来执行HTTP GET。 因此,例如:

$ curl http://127.0.0.1:9001/

wget也可以用于此目的。 如果连接被拒绝,则可能是您的节点服务器根本没有运行或未配置为在其他端口上侦听。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM