作者surimodo (摇滚少女!! 活力棉花糖!!)
看板MIS
标题[请益] Nginx 同主机多伺服器配静态资源
时间Sun Mar 5 18:53:18 2023
同台电脑配置多个伺服器
类似这样
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或其他伺服器的
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 111.243.150.14 (台湾)
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MIS/M.1678013600.A.8A6.html
※ 编辑: surimodo (111.243.150.14 台湾), 03/05/2023 18:54:58
1F:→ tomsawyer: rewrite 03/05 19:32
2F:→ tomsawyer: rewrite ^/server3/(.*) /$1 break; 试试 03/05 19:35
3F:→ surimodo: 後来小改伺服器专案 url加前缀区分 03/06 08:01