I tried to clean up my urls on my reverse proxy nginx config. My config looks like this

upstream blog {
server {
        listen       80;
        server_name  domain.tdl www.domain.tdl;

        rewrite ^/index.html$ / redirect;
        rewrite ^(/.+)/index.html$ $1 redirect;

        if ($request_uri ~* ".html") {
            rewrite (?i)^(.*)/(.*)\.html $1/$2 redirect;

        location / {
            rewrite ^/(.*) /$1 break;
            proxy_pass http://blog;

As long as the port in my blog upsteam is 80 everything works fine. But if I change that to something else nginx will try to redirect my requests to domain.tdl:port which obviously doesn't work. I tired many combinations of proxy_set_header and proxy_redirect but nothing works for me.

As requested a bit more details all outputs are from curl -Lv:

I set ip:port to ip:8000

< HTTP/1.1 301 Moved Permanently
< Location: http://blog:8000/archiv/

I set proxy_pass to http://blog http://domain.tdl

< HTTP/1.1 301 Moved Permanently
< Location: http://domain.tdl/:8000/archiv/

I set ip:80

< HTTP/1.1 301 Moved Permanently
< Location: http://domain.tdl/archiv/

Has anyone a idea why this happens or how I can fix that?

  • What do you want the input, output pair be and what it is now? I'm having hard time understanding what are you trying to accomplish.
    – Fox
    Jun 26 '15 at 21:56
  • Long story short, my redirects don't work if the upstream has something else than port 80 Jun 26 '15 at 22:01
  • You probably shouldn't make long story short. Quite the opposite. If your upstream is set like upstream blog { ip:8888; } What URL do you enter and what exactly happens (include error message, response code, whatever), or what do you expect to happen?
    – Fox
    Jun 26 '15 at 22:07
  • @Fox sorry I misunderstood you, I updated the question now with more details Jun 27 '15 at 12:41
  • No problem. Just please, tell me the URL you used with the curl. Thanks.
    – Fox
    Jun 27 '15 at 22:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.