导读
如何优化下列配置
server {
listen 80;
location /app {
proxy_pass http://www.taobao.net:5080;
}
location /auth {
proxy_pass http://www.taobao.net:5080;
}
location /api {
proxy_pass http://www.taobao.net:5080;
}
location /images {
proxy_pass http://www.taobao.net:5080;
}
location / {
proxy_pass http://127.0.0.1:8000;
}
}
当 http://www.taobao.net:5080 发生变化就要改四个地方
正文
nginx配置文件是支持变量的
server {
set $service http://127.0.0.1:8000;
listen 80;
location /app {
proxy_pass $service;
}
location /auth {
proxy_pass $service;
}
location /api {
proxy_pass $service;
}
location /images {
proxy_pass $service;
}
location / {
proxy_pass http://127.0.0.1:8000;
}
}
结语
以前是内事不决问百度,外事不决问谷歌,现在还是问自己最靠谱.
网友评论