coolicer
V2EX  ›  Node.js

你们用 Nginx 代理 nodejs 的端口,配置文件是怎么写的

  •  
  •   coolicer · Apr 14, 2014 · 4738 views
    This topic created in 4591 days ago, the information mentioned may be changed or developed.
    server {
    ____listen 80;

    ____server_name your-domain.com;

    ____location / {
    ________proxy_pass http://localhost:{YOUR_PORT};
    ________proxy_http_version 1.1;
    ________proxy_set_header Upgrade $http_upgrade;
    ________proxy_set_header Connection 'upgrade';
    ________proxy_cache_bypass $http_upgrade;
    ____}
    }

    这样的设置觉得简单了点,能不能共享一下你们的配置。
    5 replies  •  1970-01-01 08:00:00 +08:00
    immjun
    immjun
    Apr 14, 2014
    1
    proxy_pass http://127.0.0.1:3000;
    就OK了
    rrfeng
    rrfeng
    Apr 14, 2014
    2
    为毛要 set 那么多 header……
    jacobbubu
    jacobbubu
    Apr 14, 2014
    3
    @rrfeng 为了支持 WebSocket
    kfll
    kfll
    Apr 15, 2014 via Android
    4
    websocket 和 其他请求分开 location 或 server 配置。

    静态资源用 nginx 处理请求的话用 try_files

    单机的话个人会比较喜欢用 socket …
    ijse
    ijse
    Apr 15, 2014
    5
    需要获取client ip的话,还需要添加
    ```
    proxy_set_header X-Real-IP $remote_addr;
    ```

    通常我还会加
    ```
    proxy_set_header HOST $http_header;
    ```

    这样可以支持非80端口.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1554 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 13:49 · PVG 21:49 · LAX 05:49 · JFK 08:49
    ♥ Do have faith in what you're doing.