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.