server {
listen 80;
server_name demo.com;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# 第一种:proxy_pass中,不带『path』,则把『匹配字符串及后缀(/api/xxx)』均带给转发地址
# 效果是: http://xxx.xxx.com/api/xxx --> http://127.0.0.1:7000/api/xxx. 转发的时候,包含了url前缀.
location ^~ /api/ {
proxy_pass http://127.0.0.1:7000;
}
# 第二种:proxy_pass中,带『path』如『/』或者『/api』,则把『排除匹配字符串后的path(/xxx)』均带给转发地址
# 效果是: http://xxx.xxx.com/api/xxx --> http://127.0.0.1:7000/xxx. 转发的时候,包含了url前缀.
location ^~ /api/ {
proxy_pass http://127.0.0.1:7000/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}