Nginx对css和js的位置进行了重构。

问题描述 投票:0回答:1

在我的配置中,我想把css和js放在luz_online_web的位置,只有访问luz_online_web*.css或.js才会被proxy_pass到。http:/110.134.0.20:8085luz_online_web。.

server {
    server_name ~(?<name>[^.]+)\.dev\.abc\.io$;
    location  / {
      proxy_pass http://110.134.0.20:8085/luz_online_web/$name$request_uri;
      include /etc/nginx/klara-reverse.conf;

    }
    location ~* ^/luz_online_web/(.+\.(css|js))$ {
        rewrite ^/luz_online_web/(.*)$ /luz_online_web/$1 break;
        proxy_pass http://110.134.0.20:8085;
    }
}

但是访问网站时,css和js文件仍然无法加载。CSS、JS文件位于luz_online_web目录下,其他文件(HTML、PNG...)存放在luz_online_webname目录下。如果把过滤器去掉,设置luz_online_web的位置,就可以加载了,js文件的路径,比如说

/luz_online_web/javax.faces.resource/jsf.js;jsessionid=SnhEULxbunZ9F6OEGRtJrMmy

enter image description here

有什么办法吗?

regex nginx nginx-location nginx-reverse-proxy
1个回答
0
投票

我的问题解决了,我把regex位置最后的$去掉了,因为.css和.js在URL中间而不是最后。

location ~* ^/luz_online_web/(.+\.(css|js)) {
    rewrite ^/luz_online_web/(.*) /luz_online_web/$1 break;
    proxy_pass http://110.134.0.20:8085;
}
© www.soinside.com 2019 - 2024. All rights reserved.