I've tried doing all of this. But to no avail. I think the record sets may be trumping my nginx config.
I have an amazon instance and am trying to figure out how to redirect from www traffic to not www with https. It seems that if I set up a CNAME record with www.domain.com to domain.com (without touching my nginx config) everything get's served up but the www never goes away. Things still get redirected to https but because the certificate doesn't know about the subdomain www, I get a red X through the https in the browser and THIS SITE IS NOT TRUSTED pages.
I then tried to set up another A record from www.domain.com to my ip address. This seems to work the same way as well. Whatever I do, I can't seem to get anything to change by changing the NGINX config. Here is my file:
server {
listen 80;
server_name www.domain.co;
return 301 https://domain.co$request_uri;
}
server {
listen 80;
server_name domain.co;
root /home/ubuntu/web/dev.domain.com;
location /static/ {
# if asset versioning is used
if ($query_string) {
expires max;
}
}
location / {
return 301 https://domain.co$request_uri;
}
}
server {
listen 443 ssl; #SSL
server_name pennypledge.co;
access_log /home/ubuntu/web/dev.domain.com/logs/access.log;
error_log /home/ubuntu/web/dev.domain.com/logs/error.log;
# no security problem here, since / is alway passed to upstream
root /home/ubuntu/web/dev.domain.com;
ssl_certificate /etc/nginx/ssl/ssl-unified.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
# serve directly - analogous for static/staticfiles
location /media/ {
# if asset versioning is used
if ($query_string) {
expires max;
}
}
location /static/ {
# if asset versioning is used
if ($query_string) {
expires max;
}
}
location / {
uwsgi_pass unix:///home/ubuntu/web/dev.domain.com/ppuwsgi.sock;
include uwsgi_params;
}
# what to serve if upstream is not available or crashes
error_page 400 /static/400.html;
error_page 403 /static/403.html;
error_page 404 /static/404.html;
error_page 500 502 503 504 /static/500.html;
# Compression
gzip on;
gzip_http_version 1.0;
gzip_comp_level 5;
gzip_proxied any;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
# Some version of IE 6 don't handle compression well on some mime-types,
# so just disable for them
gzip_disable "MSIE [1-6].(?!.*SV1)";
gzip_vary on;
}