Forcing SSL;

António P. P. Almeida appa at perusio.net
Tue Feb 8 19:38:33 MSK 2011


On 8 Fev 2011 16h14 WET, david at styleflare.com wrote:

> Wouldn't that create an infinite loop?

No because they're listening on different ports. No need for an
if. Use two server blocks as suggested.

The server block for port 80 always does a permanent redirect do the
the same server but listening on 443 with a SSL socket. 

All the page processing happens at the server block for port 443.

server {
    ## This is to avoid the spurious if for sub-domain name
    ## rewriting. See http://wiki.nginx.org/Pitfalls#Server_Name.
    listen [::]:80;
    server_name example.com;
    rewrite ^ https://example.com$request_uri? permanent;
} # server domain rewrite.

server {
    listen [::]:443 ssl;
    server_name example.com;
    (...)
}    
--- appa


     



More information about the nginx mailing list