1、代理多個前端服務(wù):
必須使用alias----(這我很不理解為什么曹步,都用root就會404缸逃,有知道的大神請告知下I倮薄)
使用alias和root區(qū)別:在于資源路徑的匹配解讀上耕突!
訪問root定義的資源路徑,會帶著location后的uri和root指定的資源路徑組合在一起去訪問服務(wù)器資源评架;alias是忽略localtion后的uri眷茁,直接訪問alias指定的資源路徑;
假設(shè)訪問的域名:www.123.com/abc 那么url = www.123.com/abc uri = abc
server {
listen 9002;
server_name loaclhost;
gzip on;
gzip_min_length 256;
gzip_comp_level 6;
gzip_types text/plain text/css text/javascript image/png image/jpg image/jpeg application/xml application/x-javascript application/javascript ;
gzip_vary on;
gzip_proxied any;
location / {
root /data/web/feparkingh5;
try_files $uri $uri/ /index.html;
index index.html index.htm;
access_log /var/log/nginx/feparkingh5_log main;
}
location /feparkinglotweb {
alias /data/web/feparkinglotweb/;
try_files $uri $uri/ /feparkinglotweb/index.html;
index index.html index.htm;
access_log /var/log/feparkinglotweb_log main;
}
location /ftp {
alias /data/web/ftp/;
try_files $uri $uri/ /index.html;
index index.html index.htm;
access_log /var/log/ftp_log main;
}
}
2纵诞、前后端or多個后端結(jié)合代理
增加相應(yīng)的location
訪問的時候后面添加對應(yīng)的路徑 :
如下圖
訪問 16.168.139.227:8082 默認(rèn)會代理到16.168.139.227:8085端口
訪問 16.168.139.227:8082/img就會自動代理到16.168.139.180/img下
image