注:轉(zhuǎn)自nginx實(shí)現(xiàn)不同域名映射到一個(gè)端口轉(zhuǎn)發(fā)到不同路徑
在一個(gè)服務(wù)器中各拷,兩個(gè)不同的域名a.site.com和b.site.com訪問80端口遵蚜,轉(zhuǎn)發(fā)到不同的地址。若通過ip訪問替废,默認(rèn)轉(zhuǎn)發(fā)至pic.mydomain.com對應(yīng)的地址
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name pic.mydomain.com;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
add_header backendIP $upstream_addr;
add_header backendCode $upstream_status;
proxy_pass http://mysvr;
proxy_set_header Host myoss.oss-cn-shenzhen-internal.aliyuncs.com;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
## one port,mutil domain,access difference route
server {
listen 80;
server_name www.mydomain.com;
location / {
proxy_pass http://localtomcatserver/mywebsite;
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location /50x.html {
}
}
upstream mysvr {
server oss-cn-shenzhen-internal.aliyuncs.com;
}
upstream localtomcatserver {
server localhost:8080;
}
這里的每個(gè)地址都是反向代理盐欺,如果需要,可以改為不同的root即可