GDouble
V2EX  ›  问与答

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

  •  
  •   GDouble · Dec 13, 2019 · 1904 views
    This topic created in 2364 days ago, the information mentioned may be changed or developed.

    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 replies    2019-12-14 00:05:57 +08:00
    lxgeek
        1
    lxgeek  
       Dec 13, 2019
    nginx 的 debug 日志开启,你看下吧
    fanpei0121
        2
    fanpei0121  
       Dec 14, 2019 via Android
    root 和 index 放到 location / {} 外面
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3258 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 12:38 · PVG 20:38 · LAX 05:38 · JFK 08:38
    ♥ Do have faith in what you're doing.