• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Help/How to? Redirect all request to https://www using Nginx+Spdy

RoldanLT

Well-known member
#3
Code:
if ($ssl_protocol = "") {
    rewrite ^/(.*) https://$http_host/$1 permanent;
}
I mean how to redirect all request to www.
Redirecting to https already works fine with this code:
Code:
server {
    server_name .domain.com;
    return 301 https://www.domain.com$request_uri;
}

server {
  listen 443 ssl spdy;
  server_name www.domain.com;
The only thing that didn't work is this:
From https://domain.com to https://www.domain.com =
 

Floren

Well-known member
#6
Here's my current config:
PHP:
server {
    server_name domain.com www.domain.com;
    return 301 https://www.domain.com$request_uri;
}

server {
    listen 443 ssl spdy;
    server_name www.domain.com;
domain.com to https://www.domain.com = Works
www.domain.com to https://www.domain.com = Works
https://domain.com to https://www.domain.com = Not working
What you have works, if it does not then look at the logs as there is something else breaking your redirection. Example: https://axivo.com
You can further cleanup that config:
Code:
server {
    server_name domain.com *.domain.com;
    return 301 https://www.domain.com$request_uri;
}
server {
    listen server_ip:443 ssl spdy default_server;
    server_name www.domain.com;
    ...
}
Oops... misread what was/wasn't working...

Code:
if ($http_host = "digitalpoint.com") {
    rewrite ^       https://www.digitalpoint.com/?  permanent;
}
That is bad... and deprecated. He has the proper solution above.
 
Last edited: