例如想訪問:https://www.foobar.com/center/
或者需要使用nginx代理,嵌套專案到某平臺里面的時候

2、nginx配置
這里使用alias ,不能用root
server {
listen 80;
server_name localhost;
client_max_body_size 200m;
location / {
#root /usr/share/nginx/html/;
index index.html index.htm;
#try_files $uri $uri/ @router;
}
location /center/ {
alias /usr/share/nginx/html/;
index index.html index.htm;
try_files $uri $uri/ /center/index.html;
}
location @router {
rewrite ^.*$ /index.html last;
}
location /alterCenter {
proxy_pass http://10.168.102.11:31351;
}
location /system {
proxy_pass http://10.168.152.52:30966;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
3、alias和root的區別
#當客戶端請求是 /center/js/util.js 時
location /center {
root /var/center/dist/;
}
#root映射結果為 /var/center/dist/center/js/util.js
#(實際util.js 檔案是在dist/js/目錄下,這樣會訪問不到資源)
location /center {
alias /var/center/dist/;
}
#alias映射結果為 /var/center/dist/util.js
4、router中的index.js添加base: ‘center’

這樣就可以實作https://www.foobar.com/center/
或者需要使用nginx代理,嵌套專案到某平臺里面了
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/296543.html
標籤:其他
