使用nginx反向代理后端服务器,打开网页找不到css,js和图片
- server {
- listen 80;
- server_name video.xxx.cn;
- proxy_set_header Host $host:$server_port;
- proxy_set_header X-Real-Ip $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- location / {
- proxy_set_header Host $host:$server_port;
- proxy_set_header X-Real-Ip $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_pass http://127.0.0.1:8083/video;
- }
- }
复制代码解决办法,既然反向代理的路径下找不到文件,那么单独指定js css文件的访问路径 修改后的配置如下: - 反向代理的路径下找不到文件,需要单独指定js css文件的访问路径。
- server {
- listen 80;
- server_name video.xxx.cn;
- proxy_set_header Host $host:$server_port;
- proxy_set_header X-Real-Ip $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- location / {
- proxy_set_header Host $host:$server_port;
- proxy_set_header X-Real-Ip $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- proxy_pass http://127.0.0.1:8083/video;
- }
- location ~ .*\.(js|css)$ {
- proxy_pass http://127.0.0.1:8083;
- }
- }
复制代码
增加两个location配置设置cs js和图片对应的反向代理,修改配置如下 - location /xxx/
- {
- proxy_pass http://172.16.90.232:86/;
- }
- # 设置js css和图片代理路径,否则前端访问找不到
- location ~ .*\.(js|css)?$ {
- expires 12h;
- proxy_pass http://172.16.90.232:86;
- }
- location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)?$ {
- expires 12h;
- proxy_pass http://172.16.90.232:86;
- }
复制代码重启nginx即可 nginx -t
nginx -s reload
|