想问一个 nginx 的问题

没用过 nginx 菜鸟想问问:

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

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

阅读 2.7k
3 个回答
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;
    }
}

可以,配置下虚拟主机就行

推荐问题
宣传栏