2017-05-02 59 views
-1

我在使用nginx的域名時遇到問題,包括www。在網址中。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; 
    } 
} 

你能幫助我嗎?謝謝!

回答

0

您需要設置您希望Nginx服務的服務器名稱。

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

所以你列出了你想用空格分隔的名字。 我假設您想要將您的所有www和非www流量重定向到https,並使用您在https配置中設置的服務器名稱,並且您的https服務器名稱是正確的。

+0

謝謝你的幫助。 –