Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 3 down vote accepted
map $uri $example_com_preferred_proto {
    default "http";
    ~^/sign-up/ "https";
    ~^/account/ "https";

server {
    listen 80;

    if ($example_com_preferred_proto = "https") {
        return 301$request_uri;

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

share|improve this answer

Your Answer


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.