i have domain, example.com
. that, have these:
- blog.example.com
- api.example.com
- books.example.com
i have acquired ssl cert root domain , subdomains.
and want redirections so:
- http://example.com => https://example.com
- http://blog.example.com => https://blog.example.com
- http://books.example.com => https://books.example.com
this example.com
nginx conf
server { listen 443 ssl default_server; root /home/django/khophi; index index.html index.htm; server_name example.com; include /etc/nginx/globalssl.conf; //ssl config } server { listen 80 default_server; server_name example.com; return 301 https://$host$request_uri; }
nginx conf blog.example.com
server { listen 443 ssl; // listens https root /var/www/html/blog; index index.php index.html index.htm; server_name blog.example.com; #include /etc/nginx/globalssl.conf; location / { try_files $uri $uri/ /index.php?q=$uri&$args; } // error pages location ~ \.php$ { //php specific things } } server { listen 80; server_name blog.example.com; return 301 https://blog.example.com$request_uri; }
books.example.com
follows similar structure blog.example.com
conf
what happens above setup?
- visit
http://example.com
redirectshttps://example.com
(just want - visit
http://blog.example.com
redirectshttps://blog.example.com
but, shows page ofhttps://example.com
in case, want:
example.com
remaindefault_server
http://example.com
redirecthttps://example.com
- all http:// requested subdomains redirect respective https:// versions
- if subdomain requested doesn't exist, should redirect default_server (https://example.com)
instead of using return
, use rewrite
instead on redirection server block on main domain , subdomains, so:
// blog.example.com server { listen 80; server_name blog.example.com; rewrite ^ https://$server_name$request_uri? permanent; }
// example.com
server { listen 80 default_server; server_name example.com; rewrite ^ https://$server_name$request_uri? permanent; }
Comments
Post a Comment