Welcome! Log In Create A New Profile

Advanced

Rewrite rules for SSL

Posted by seminal 
Rewrite rules for SSL
January 05, 2012 01:14PM
I'm trying to redirect only certain requests to use ssl and not my
whole site but I can't figure how to escape this redirect loop. Here's
my server block where I tried using a location block to redirect
traffic:

server {
listen 80;
server_name example.com;
rewrite ^ http://www.example.com$request_uri? permanent;
}

server {
listen 80;
listen 443 ssl;
ssl_certificate /srv/ssl/sslchain.crt;
ssl_certificate_key /srv/ssl/example.com.key;
server_name www.example.com;

location / {
root /usr/local/bin/rails/example/public;
index index.html index.htm;
passenger_enabled on;
}

location /users/sign_up {
rewrite ^ https://www.example.com/users/sign_up break;
}

location /users/sign_in {
rewrite ^ https://www.example.com/users/sign_in break;
}

if ($host !~* ^(example.com|www.example.com)$){
return 502;
}

location ~* ^.+\.(jpg|jpeg|png|gif|css|js)$ {
root /usr/local/bin/rails/example/public;
passenger_enabled on;
expires 31d;
}

error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}

I've also tried 'if' blocks....
if ($request_uri ~* /users/sign_up ) {
rewrite ^ https://www.example.com/users/sign_up break;
}

And I've tried it without the 'break' argument. How can I redirect
without getting stuck in a loop? Thanks.
Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 148
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready