nginx配置多个应用通过80端口访问

1、让域名供应商解析pan.a.com和www.a.com到自己的服务器,让pan.a.com指向localhost:8081,让www.a.com指向localhost:8080

配置如下

upstream www.a.com {
    server localhost:8080;
}
upstream pan.a.com {
    server localhost:8081;
}

server {
    listen 80;
    server_name www.a.com;
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://www.a.com;
    }
}
server {
    listen 80;
    server_name pan.a.com;
    location / {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://pan.a.com;
    }
}

 


2、还可以用nginx配置让http://a.com/admin/指向http://a.com:8080,让http://a.com/product/指向http://a.com:8081

配置如下

upstream admin_server{
    server a.com:8080;
}
upstream product_server{
    server a.com:8081;
}

server {
    listen 80;
    server_name a.com;
    location /product/ {
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://product_server/;
}

location /admin/ {
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_pass http://admin_server/;
}
}

  


原文链接:https://blog.csdn.net/shuangyueliao/article/details/83109734

posted @ 2019-08-12 10:07  深水是沉默  阅读(6051)  评论(0编辑  收藏  举报