問題現象:
nginx配置反向代理后,網頁可以正常訪問,但是頁面上的js、css和圖片等資源都無法訪問。
(1)nginx配置如下:
(2)域名訪問:js css文件無法加載;
(3)IP訪問:js css文件可以正常加載;
(4)CI框架下無法訪問
配置此例即可:
location / { proxy_pass http://127.0.0.1:8000; include naproxy.conf; }
解決方法:
nginx配置文件中,修改為如下配置:
location ~ \.php$ { proxy_pass http://127.0.0.1:8000; include naproxy.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; proxy_pass http://127.0.0.1:8000; include naproxy.conf; } location ~ .*\.(js|css)?$ { expires 12h; proxy_pass http://127.0.0.1:8000; include naproxy.conf; }
需要把靜態文件也添加反向代理設置。
原因分析:
反向代理的路徑下找不到文件,這里需要單獨指定js和css文件的訪問路徑。