分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 网页技术

nginx反向代理转发后页面上的js css文件无法加载【原创】

发布时间:2023-09-06 02:25责任编辑:胡小海关键词:js反向代理nginx

故障现象:nginx做代理转发后,发现页面上的js css文件无法加载,页面样式乱了。

原因:没有配置静态资源 解决js css文件无法加载无法访问的问题

解决办法:

修改配置文件nginx.conf,在server字段中添加黄色标注部分

 ???????server { ???????listen ??????80; ???????server_name ?test.com; ???????#charset koi8-r; ???????access_log ?logs/opc.access.log ?main; ???????????????location / { ???????????????????????proxy_pass http://opcservice/hnairweb/; ???????????????????????proxy_redirect ????off; ???????????proxy_set_header ??Host $host; ???????????proxy_hide_header Server; ???????????proxy_set_header X-Real-IP ?????$remote_addr; ???????????proxy_set_header X-Forwarded-For $remote_addr; ???????????proxy_connect_timeout ?????10; ???????????proxy_send_timeout ????????10; ???????????proxy_read_timeout ????????10; ???????????proxy_intercept_errors ????on; ???????????proxy_buffering ???????????off; ???????????????}
     #配置静态资源 解决js css文件无法加载无法访问的问题,注意末尾不能有 /                 location ~ .*\.(js|css|jpg|jpeg|gif|png|ico|pdf|txt)$ {
                        proxy_pass http://opcservice;
         }   # location ~ .*\.(js|css)$ {# ????????????proxy_pass http://opcservice;# ????????} ???????#error_page ?404 ?????????????/404.html; ???????# redirect server error pages to the static page /50x.html ???????# ???????error_page ??500 502 503 504 ?/50x.html; ???????location = /50x.html { ???????????root ??html; ???????} ???}

然后重新加载nginx配置即可

参考

nginx配置反向代理后,网页可以正常访问,但是页面上的js css文件无法加载 - Jay丶的个人空间 - 开源中国 https://my.oschina.net/u/2276456/blog/1838760

nginx反向代理转发后页面上的js css文件无法加载【原创】

原文地址:https://www.cnblogs.com/paul8339/p/10084192.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved