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
配置如下:更多nginx技术文档可以查看nginx技术书册
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/;
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。