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

is there a way to configure Nginx to read from a line-by-line file to determine when HTTPS should be enforced rather than putting all the URLS in a conditional check? Or is there a way to combine the two? Two areas of concern are organization and the ability long term to manage those urls. We are thinking of moving this to the application layer but Nginx seems faster in evaluating this. Currently we are just using a regular expression.

share|improve this question
    
Why not just force everything to TLS? –  EEAA Apr 22 '13 at 23:32

1 Answer 1

up vote 3 down vote accepted
map $uri $example_com_preferred_proto {
    default "http";
    ~^/sign-up/ "https";
    ~^/account/ "https";
}

server {
    listen 80;
    server_name example.com;

    if ($example_com_preferred_proto = "https") {
        return 301 https://example.com$request_uri;
    }

    # root /var/www/example.com/html;
    # other stuff
    # ...
    # location / {
    #     ...
    # }

}
share|improve this answer

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.