I have a django web app which run on server with IP address xx.xxx.105.49
and domain as www.example1.com
Below is my nginx configuration
server {
listen 80;
server_name example1.com www.example1.com ;
location / {
return 301 https://www.example1.com$request_uri;
}
}
server {
listen 443 ssl;
server_name example1.com www.example1.com;
ssl_certificate /etc/ssl/company/company.com.chained.crt;
ssl_certificate_key /etc/ssl/company/www.company.com.key;
ssl_session_timeout 20m;
ssl_session_cache shared:SSL:10m; # ~ 40,000 sessions
ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # SSLv2
# ssl_ciphers ALL:!aNull:!eNull:!SSLv2:!kEDH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+EXP:@STRENGTH;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
client_max_body_size 20M;
location / {
proxy_pass http://127.0.0.1:8001;
proxy_connect_timeout 300s;
proxy_read_timeout 300s;
}
location /static/ {
alias /home/apps/webapp/company/new_media/;
}
location /media/ {
alias /home/apps/webapp/company/media/;
}
}
when i type www.example1.com
or example1.com
from browser it take me to https://www.example1.com
as expected but, now I have configured another domain(example2.company.com
) to route to the same server (xx.xxx.105.49)
and the actual problem is
when ever i type https://example2.company.com
(secure), server was serving me the webapp with same domain example2.company.com
But when i use http://example2.company.com
, my server was redirecting to www.example1.com
which was not i want, so how can make some changes to the above nginx config file in such a way that if some one tries to access example2.company.com
using http or https it should redirect to https://example2.company.com
like below
server {
listen 80;
server_name example1.com www.example1.com ;
location / {
return 301 https://www.example1.com$request_uri;
}
}
server {
listen 80;
server_name example2.company.com www.example2.company.com ;
location / {
return 301 https://www.example2.company.com$request_uri;
}
}