nginx improperly forwards to https, adds two trailing slashes when rewriting

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2010-05-27T23:16:48Z Indexed on 2010/05/27 23:21 UTC
Read the original article Hit count: 275

Filed under:

I'm using nginx as a proxy for a django project on mod_wsgi and to serve the static content.

I have two domain names for it: asdf-example.com and asdfexample.com. I want to use rewrites to redirect everything to www.asdf-example.com

They're not quite working the way they should:

asdf-example.com forwards to https:// www.asdf-example.com, which fails because I'm not using SSL. Though asdf-example.com/search forwards to http://....

asdfexample.com and www.asdfexample.com both forward to www.asdf-example.com//, which looks weird.

My config file:

server {
        listen 80;
        server_name asdf-example.com asdfexample.com;

        if ($host ~* ^asdf-example\.com){
                rewrite ^(.*)$ http://www.asdf-example.com/$1 permanent;
        }

        if ($host ~* ^asdfexample\.com){
                rewrite ^(.*)$ http://www.asdf-example.com/$1 permanent;
        }

        if ($host ~* ^www\.asdfexample\.com){
                rewrite ^(.*)$ http://www.asdf-example.com/$1 permanent;
        }
        ...

Thanks

© Stack Overflow or respective owner

Related posts about nginx