nginx配置代理
nginx中server块中,listen 80 跟外部web浏览器访问的端口没有关系,比如外部是30000端口,一样可以把访问放入nginx,其中的匹配优先级是:如果listen中写了IP和端口,会先匹配相应的IP,再匹配server_name中的域名,如果匹配,就把请求丢给对应的location来处理。
server {
listen 80;
listen [::]:80;
server_name frontvue-xxx.com;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
location /auth {
proxy_pass http://xxx.com:30000;
}
location /api-apm {
proxy_pass http://abcxxx.com:30000;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
proxy_pass有/,实际访问地址(代理后的url)就没有location的地址,proxy_pass没有/(上面的请求就没有 / ),实际访问地址就会带上location 的部分