记录集& nginx将流量从www重定向到常规无www https

时间:2014-11-28 18:12:33

标签: nginx cname a-records

我已尝试完成所有this。但无济于事。我认为记录集可能胜过我的nginx配置。

我有一个亚马逊实例,我正在尝试弄清楚如何从www流量重定向到不使用https的www。似乎如果我在www.domain.com上设置一个CNAME记录到domain.com(没有触及我的nginx配置),一切都会被提供,但www永远不会消失。事情仍然被重定向到https,但由于证书不知道子域名www,我在浏览器中通过https得到一个红色的X,而且这个站点不受信任页面。

然后我尝试将另一条A记录从www.domain.com设置到我的IP地址。这看起来也是一样的。无论我做什么,我都无法通过更改NGINX配置来改变任何事情。这是我的档案:

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;
}

0 个答案:

没有答案
相关问题