Nginx SSL/Subdomain/IP redirect Nginx SSL/Subdomain/IP redirect nginx nginx

Nginx SSL/Subdomain/IP redirect


Please check running with following config, this should work.

#This would serve all your content.server {  listen 443 ssl spdy default deferred;  server_name example.com;  ... more configs}#https calls to anything except example.com would be redirected here    server {  listen 443 ssl spdy default deferred; #(Can also use only : "listen 443;")  server_name *.example.com 123.123.123.123;  return 301 https://example.com$request_uri;}#All port 80 redirection to https://example.comserver {  listen 80;  server_name example.com *.example.com 123.123.123.123;  return 301 https://example.com$request_uri;}


I used this pattern to solve a similar problem:

server_name   ~^(?<subdomains>.+\.)?(?<domain>[^.]+\.[^.]+)$;if ($domain != 'example.com') {        rewrite ^/(.*)$  http://${subdomains}example.com/$1  permanent;}

And so on