Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

This is what I do:

Because /api system has problem with HTTPS, I have to serve it under HTTP. The rest I force them to be in HTTPS. However, in my django system, redirects gives me back http. It may have to do with django, but for now, I want to rewrite all HTTP to HTTPs. I normally would put that inside the 80 server block, but I want to keep /api as HTTP.

How can I do that using rewrite?

Thanks.

    server {
        listen 80;
        server_name localhost 127.0.0.1;
        server_name_in_redirect off;
        client_max_body_size 100M;

        location /api {
            proxy_set_header Host $host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_pass http://localhost:5050;
            proxy_redirect default;
        }

    }
    server {

        listen 443;
        ssl on;

        location /app1 {
         ....
         proxy_pass http://localhost:1234;
        }

        location /app2 {
         ... 
         proxy_pass http://localhost:5678;
        }
}
share|improve this question
add comment

1 Answer

Ah. I just tried something and it looks like it's working.

if ($request_uri !~ (/api)){
    rewrite     ^(.*)   https://$http_host$1 permanent;
}

and then leave everything else in the 80 block intact... Not gonna check my answer off...

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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