Nginx反向代理web网站时,容易出现css和图片丢失的情况,要解决这个问题
需要添加location ~ .*
如:
server {
listen 80;
server_name abc.ccc.com;
location / {
proxy_pass http://172.16.11.11:8088/samc/;
#添加代理header
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#set_real_ip_from 0.0.0.0/0;
#real_ip_header X-Forwarded-For;
}
location /myweb/ {
proxy_pass http://172.16.11.11:8088/samc/;
#添加代理header
proxy_set_header Host $host;
proxy_set_header X-real-ip $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
#set_real_ip_from 0.0.0.0/0;
#real_ip_header X-Forwarded-For;
}
location ~ .*(/myweb).*.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ {
proxy_pass http://172.16.11.11:8088; #匹配实际端的口地址(这里不能加入项目名)
}
location ~ .*.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ {
proxy_pass http://172.16.11.11:8088;
}
}