V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
GDouble
V2EX  ›  问与答

nginx 配置反向代理 到 node.js 出了点问题,求助 v 友

  •  
  •   GDouble · 2019-12-13 10:57:13 +08:00 · 1009 次点击
    这是一个创建于 1568 天前的主题,其中的信息可能已经有所发展或是发生改变。

    node 监听的是 8080 端口 想用 nginx80 端口代理到 8080 端口 网页相关的静态资源已经放到 nginx 默认的 html 下的 client 文件夹里面 node.js 用了 socket.io 访问一直 404 配置参考了一下网上的 如下: server { listen 80; server_name localhost;

        #charset koi8-r;
        access_log /var/log/nginx/dev.log;
        error_log /var/log/nginx/dev.error.log debug;
        #access_log  logs/host.access.log  main;
    
        location / {
            root   html/client;
            index  index.html index.htm;
            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;
    
            # nginx 1.13 版本以上,支持 websocket
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
    
            proxy_redirect off;
    
            #代理设置最关键的一行
            proxy_pass http://127.0.0.1:8080;
            break;
        }
    
        location ~.*\.(gif|jpg|jpeg|png|bmp|swf)$ {
            expires 30d;
        }
    
    2 条回复    2019-12-14 00:05:57 +08:00
    lxgeek
        1
    lxgeek  
       2019-12-13 12:46:22 +08:00
    nginx 的 debug 日志开启,你看下吧
    fanpei0121
        2
    fanpei0121  
       2019-12-14 00:05:57 +08:00 via Android
    root 和 index 放到 location / {} 外面
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2636 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 15:33 · PVG 23:33 · LAX 08:33 · JFK 11:33
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.