我正在嘗試使用 nginx 托管兩個反應應用程式,每個作業都需要查詢引數 ?test=1
location / {
alias /root/phone_build/;
index index.html;
try_files $uri /index.html$is_args$args =404;
}
location /web_build {
alias /root/web_build/;
index index.html;
try_files $uri /index.html$is_args$args =404;
}
#location / {
location /api {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_read_timeout 300s;
proxy_send_timeout 300s;
proxy_connect_timeout 300s;
proxy_cache_bypass $http_upgrade;
}
我嘗試使用 ?$query_string 但仍然無法正常作業。有什么建議嗎?謝謝你
uj5u.com熱心網友回復:
您使用try_files不正確。檔案術語與檔案名匹配,不需要$is_args$args,否則,當您向請求添加查詢字串時,您將簡單地強制404回應。
另外,使用root代替alias. 該alias指令僅在特殊情況下才需要。
嘗試:
index index.html;
location / {
root /root/phone_build;
try_files $uri /index.html =404;
}
location /web_build {
root /root;
try_files $uri /web_build/index.html =404;
}
location /api {
...
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/471259.html
標籤:nginx
