2016-03-01 41 views
1

我有Nginx服务器的新手。我有网站的网址,我正在使用Ngnix服务器配置的try_file。这些都是一些网址:静态内容不加载与Nginx服务器的子网址尝试文件

http://localhost:81/test-url 
http://localhost:81/test-url/abc 

如果上午尝试抓取该网址

http://localhost:81/test-url 

那么它做工精细,所有的CSS将被加载fine.But当我尝试抓取该网址

http://localhost:81/test-url/abc 

然后它没有加载css和js文件。由于CSS路径将被更改为

http://localhost:81/test-url/css/style.css 

,但我实际路径需要的是

http://localhost:81/css/style.css 

我的Nginx服务器配置为

upstream dev { 
     server 127.0.0.1:9130; 
    } 

    server { 
     rewrite_log on; 
     listen [::]:81; 
     server_name localhost; 

     location/{ 
      root D:/project/src/main/webapp; 
      try_files $uri /index.html; 
     } 
     location ~ ^/app/.+ { 
      proxy_pass http://dev; 
       proxy_set_header Host $http_host; 
     } 
     location ~ /api/.+ { 
      proxy_pass http://dev; 
      proxy_set_header Host $http_host; 
     } 
     location ~ /client/.+ { 
      proxy_pass http://dev; 
      proxy_set_header Host $http_host; 
     } 
     location ~ /admin/.+ { 
      proxy_pass http://dev; 
      proxy_set_header Host $http_host; 
     } 
     location ~ /oauth/.+ { 
      proxy_pass http://dev; 
      proxy_set_header Host $http_host; 
     } 
     location ~ /webhook/.+ { 
      proxy_pass http://dev; 
      proxy_set_header Host $http_host; 
     } 
    } 

所以,请任何人能帮助我。如何解决这个问题与Nginx的服务器。我使用角URL加载网站。

+0

请求您的css以绝对路径开始,斜杠'/' – ClojureMostly

回答

2

我已经用在head标签上添加

<base href="/"> 

找到了解决办法。