Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have managed to get all /admin requests redirected to https by:

server {
    listen 80;

    location /admin {
        rewrite ^ https://$server_name$request_uri?$args permanent;
    }
}

But can't figure out how to get all https requests that are not within /admin redirected to http, so far I have:

server {
    listen       443;

    location ~ /admin {
        rewrite ^ http://$server_name$request_uri?$args permanent;
    }
}

EDIT:

I have got the redirects working as required but can't stop the /admin url going to 404. It feels like I need to put something in the empty block.

server {
    listen       443;

    location /admin {

    }   

    location / {
        rewrite ^ http://$server_name$request_uri?$args permanent;
    }
}

Thanks

share|improve this question

closed as off topic by ChrisF, BBlake, Randolph West, Mechanical snail, slhck Sep 13 '12 at 18:46

Questions on Super User are expected to relate to computer software or computer hardware within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
I think this may answer my question wiki.nginx.org/HttpCoreModule#location. "there is no syntax for NOT matching a regular expression. Instead, match the target regular expression and assign an empty block, then use location / to match anything else." –  sebastyuiop Sep 13 '12 at 0:59
    
Please do not cross post – your question will be migrated to a better site if it's off topic somewhere. –  slhck Sep 13 '12 at 18:46

1 Answer 1

You need to somehow serve something when /admin is loaded. So decide what you want to be served.

For instance:

location /admin {
    try_files $uri $uri/ =404;
}

will serve static files in that directory. Add whatever you need.

share|improve this answer

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