2017-09-13 77 views
0

我做了一个代理页:http://destsrv:8089/index.html 它包含链接到像绝对路径:href="/static/bootstrap/css/bootstrap.min.css"Nginx的proxy_pass位置的绝对路径

而且nginx的配置,如:

location /admin/ { 
       proxy_pass http://destsrv:8089/; 
     } 

虽然访问http://myproxy/admin/index.html 当它是试图获得.css从: http://myproxy/static/bootstrap/css/bootstrap.min.css

但预计是: http://myproxy/admin/static/bootstrap/css/bootstrap.min.css

怎么办?

回答

1

试试这个

location /admin/ { 
    proxy_pass http://destsrv:8089/; 
    sub_filter_once off; 
    sub_filter "http://destsrv:8089/" "$scheme://$host/admin"; 
    sub_filter 'href="/' 'href="/admin/'; 
    sub_filter "href='/" "href='/admin/"; 
} 

你基本上要使用过滤器

+0

固定的网址,谢谢!这是工作! – hades

+0

什么是href =“// sth”类型的链接?是否可以在同时更换href =“/ sth”时设置不接触它们的规则? – hades

+0

试试这个'sub_filter''' \ n ';'。删除其他href的人 –