[請益] Nginx 同主機多伺服器配靜態資源

作者: surimodo (好吃棉花糖)   2023-03-05 18:53:18
同台電腦配置多個伺服器
類似這樣
location /server3 {
proxy_pass http://127.0.0.1:7000/;
}
location /server2 {
proxy_pass http://127.0.0.1:8000/;
}
location / {
proxy_pass http://127.0.0.1:9000/;
}
如果打開 server3 http://localhost/server3
其中有引入靜態資源路徑是 ./index.css
找的會是根伺服器 localhost / 的靜態資源
要用 localhost:7000/index.css 才能正確讀到
請問我要怎麼配置
才能即使 根伺服器 和 server3 都有引用 ./index.css
也能正確分別引用
使用 http://localhost/server3
能正確讀取到 ./index.css
而不是404或其他伺服器的
作者: tomsawyer (安安)   2023-03-05 19:32:00
rewriterewrite ^/server3/(.*) /$1 break; 試試
作者: surimodo (好吃棉花糖)   2023-03-06 08:01:00
後來小改伺服器專案 url加前綴區分

Links booklink

Contact Us: admin [ a t ] ucptt.com