node.js: route request to different port on same host

前端 未结 3 1878
孤街浪徒
孤街浪徒 2021-01-17 23:07

I have a host computer which serves a number of webapplications (not node.js based). It does this using different ports. This means that for example the following applicatio

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-17 23:55

    You probably better use Nginx setting up a reverse proxy with different locations per application.

    It's not what you ask for because it does not use node.js, but if it's the only purpose, Nginx really suits your needs.

    For example a Nginx configuration file like should work the way you want :

    server {
        listen 80;
    
        server_name myapp.com;
    
        location /app1 {
            proxy_pass http://APP_PRIVATE_IP_ADDRESS:3000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        } 
    
        location /app2 {
            proxy_pass http://APP_PRIVATE_IP_ADDRESS:3001;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        } 
    
        location /app3 {
            proxy_pass http://APP_PRIVATE_IP_ADDRESS:3003;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
        } 
    }
    

提交回复
热议问题