I am replacing lighttpd with nginx on my development server. I got it working with PHP and SSL, but I'm stumped by what should be a simple rewrite. I need to rewrite URLs from

http[s]://dev.foo.com/signup/123456

to

http[s]://dev.foo.com/signup/index.php?attcode=123456

The rule I am using is:

rewrite ^/signup/([0-9]+)$  /signup/index.php?attycode=$1 last;

I have tried numerous variations on this, moved it around, put it inside a location block. What happens is the URL is rewritten to:

http://dev.foo.com/dev.foo.com/signup/123456

The hostname is inserted, and it seems to always lose https and go to http.

My nginx.com server section is below. I have read and re-read the nginx docs (as they are) and searched the nginx mailing list, but nothing I've tried has solved this problem.

Ubuntu 8.0.4 LTS in case that matters.

Thanks.


server {
    listen      80;
    listen      443 default ssl;
    server_name dev.foo.com   dev.bar.com   localhost;
    root        /var/www/foo;
    index       index.php index.html;
    # ssl cert stuff omitted
    charset utf-8;
    access_log  /var/log/www/dev.access.log  main;

    location ~ /\. {
        deny  all;
    }   

    location ~* ^.+\.(inc|tpl|sql|ini|bak|sh|cgi)$ {
        deny all;
    }   

    location ~* ^/(scripts|tmp|sql)/ {
        deny all;
    }   

    rewrite ^/robots.txt$         /robots_nocrawl.txt break;
    rewrite ^/signup/([0-9]+)$    /signup/index.php?attycode=$1 last;

    location / { 
        try_files $uri $uri/ /error_404.php;
    }   

    location ~ \.php$ {
        fastcgi_pass localhost:51115;
        fastcgi_index index.php;
        fastcgi_intercept_errors on; 
        include fastcgi_params;
        fastcgi_param SERVER_NAME       $http_host;
        fastcgi_param SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    }

    error_page  404              /error_404.php;
}
link|improve this question
feedback

1 Answer

Try:

rewrite ^/signup/([0-9]+)$  https://$server_namesignup/index.php?attycode=$1 last;

if it comes from HTTP then nginx is gonna try and push it back to HTTP and I think it also rewrites to HTTP by default unless you specify a protocol.

link|improve this answer
I wrote "always lose https and go to http." Even if I put a protocol in the rewrite rule destination. I never did get this to work. Sticking with lighttpd. – gregjor Nov 27 '10 at 8:38
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.