【问题标题】:www in domain not working - nginx域中的 www 不起作用 - nginx
【发布时间】:2017-09-29 19:53:35
【问题描述】:

当您包含 www 时,我在使用 nginx 使域工作时遇到问题。在网址中。

mydomain.com --> 工作但 www.mydomain.com --> 不 工作

配置文件:

server {
    listen 80;
    listen [::]:80;
    #server_name git.mydomain.com;
    return 301 https://$host$request_uri;
}

server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;
    server_name git.www.mydomain.com;
    # certs sent to the client in SERVER HELLO are concatenated in ssl_certific$
    ssl_certificate /etc/nginx/ssl/mydomain.com.crt;
    ssl_certificate_key /etc/nginx/ssl/mydomain.com.key;
    ssl_session_timeout 1d;
    ssl_session_cache shared:SSL:50m;
    ssl_session_tickets off;

    # Diffie-Hellman parameter for DHE ciphersuites, recommended 4096 bits
    ssl_dhparam /etc/nginx/ssl/dhparam.pem;

    # modern configuration. tweak to your needs.
    ssl_protocols TLSv1.2;
    ssl_ciphers 'ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDH$
    ssl_prefer_server_ciphers on;

    # HSTS (ngx_http_headers_module is required) (15768000 seconds = 6 months)
    add_header Strict-Transport-Security max-age=15768000;

    location / {
            try_files $uri $uri/ =404;
    }
}

你能帮帮我吗?谢谢!

【问题讨论】:

    标签: ssl nginx web https dns


    【解决方案1】:

    您需要设置您希望 Nginx 提供服务的服务器名称。

    server {
        listen 80;
        listen [::]:80;
        server_name mydomain.com www.mydomain.com;
        return 301 https://$host$request_uri;
    }
    

    所以你列出你想用空格分隔的名字。 我假设您希望使用您在 https 配置中设置的服务器名称将所有 www 和非 www 流量重定向到 https,并且您的 https 服务器名称是正确的。

    【讨论】:

    • 感谢您的帮助。
    猜你喜欢
    • 2012-04-14
    • 2020-07-18
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 2017-01-11
    • 1970-01-01
    • 2014-10-13
    相关资源
    最近更新 更多