coolicer
V2EX  ›  Node.js

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

  •  
  •   coolicer · Apr 14, 2014 · 4459 views
    This topic created in 4440 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
        1
    immjun  
       Apr 14, 2014
    proxy_pass http://127.0.0.1:3000;
    就OK了
    rrfeng
        2
    rrfeng  
       Apr 14, 2014
    为毛要 set 那么多 header……
    jacobbubu
        3
    jacobbubu  
       Apr 14, 2014
    @rrfeng 为了支持 WebSocket
    kfll
        4
    kfll  
       Apr 15, 2014 via Android
    websocket 和 其他请求分开 location 或 server 配置。

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

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

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

    这样可以支持非80端口.
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5427 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 07:48 · PVG 15:48 · LAX 00:48 · JFK 03:48
    ♥ Do have faith in what you're doing.