search

Home  >  Q&A  >  body text

node.js - 想问一个 nginx 的问题

没用过 nginx 菜鸟想问问:

假如我服务器运行2个 nodejs 程序,一个是 localhost:3000,另一个是 localhost:8080

我能不能把域名 a.com 指向 localhost:3000,把域名 b.com 指向 localhost:8080?

天蓬老师天蓬老师2780 days ago508

reply all(3)I'll reply

  • 天蓬老师

    天蓬老师2017-04-17 14:59:32

    server{  
        listen 80;  
        server_name a.com;
    
        location / {  
            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;  
            proxy_pass http://127.0.0.1:3000;  
            proxy_redirect off;
        }
    }
    
    server{  
        listen 80;  
        server_name b.com;
    
        location / {  
            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;  
            proxy_pass http://127.0.0.1:8080;  
            proxy_redirect off;
        }
    }

    reply
    0
  • 巴扎黑

    巴扎黑2017-04-17 14:59:32

    Yes, nginx upstream reverse proxy

    There happens to be an article

    https://segmentfault.com/a/11...

    reply
    0
  • 高洛峰

    高洛峰2017-04-17 14:59:32

    Yes, just configure the virtual host

    reply
    0
  • Cancelreply