开发者

nginx rewrite url problem need help [closed]

Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 10 years ago.

Improve this question

I am 开发者_如何学Cnew to nginx, and I have installed php (using port 8888) and nginx (using port 80), and I have a static html page as www.aa.com:8888/news/html/about/aboutus/index.html, now I would like to use www.aa.com/test/aboutus.html to visit it, and when doing this, the URL in the browser should not change. How to do this?

I tried some ways, but the link in the browser will just redirect to the new URL string ...

My sample config in the conf file of nginx as below:

    location ^~ /test/aboutus.html {
        proxy_pass   http://127.0.0.1:8888;
        proxy_redirect   default;
        rewrite ^/test/aboutus.html$ /news/html/about/aboutus last;
        break;
    }

Thanks a lot!


Nobody else has answered, so I guess I will give it a shot.

According to the documentation for proxy_pass:

A special case is using variables in the proxy_pass statement: The requested URL is not used and you are fully responsible to construct the target URL yourself.

So if you can get a variable in there, you can just provide the full URL and not worry about rewrite. Something like this:

location /test/aboutus.html {
    proxy_pass $scheme://127.0.0.1:8888/news/html/about/aboutus;
}

I have not tested this (sorry).

[update]

One more idea:

location /test/aboutus.html {
    proxy_pass $scheme://127.0.0.1:8888/news/html/about/aboutus;
    proxy_redirect $scheme://127.0.0.1:8888/news/html/about/aboutus $scheme://$host/test/aboutus.html
}

The idea is to map the Location header in the reply back to what you want the client to show in the browser. That is what proxy_redirect is for (although the "default" setting should have worked I think).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜