2017-03-06 67 views
0

所以我一个网站,我不能透露网址到目前。所以我将这个问题称为www.example.com。Nginx没有重定向没有www到www

我希望任何尝试访问我的网站以重定向到HTTPS :: //www.example.com。然而,这种情况并非如此。我设法让它将http重定向到https。

,如果我去到example.com,它重定向到www.example.com,但如果我尝试其他途径,例如example.com/videos它只是重定向到https://example.com/videos,而不是https://www.example.com

这里是我的nginx的配置文件:

server{ 

    listen 80; 
    server_name example.com www.example.com; 
    rewrite ^/(.*) https://www.example.com/$1 permanent; 
} 

server { 
    listen 443 ssl; 

    server_name example.com www.thevirtualpornwebsite.com; 
    root /var/www/example_folder/public; 


    index index.php index.html index.htm index.nginx-debian.html; 


    ssl_certificate /home/example_user/example.com.chained.crt; 
    ssl_certificate_key /home/example_user/example.com.key; 

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; 
    ssl_prefer_server_ciphers on; 
    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH'; 


    location/{ 
     rewrite ^/(.*)/$ /$1 permanent; 
     try_files $uri $uri/ /index.php?$query_string; 
    } 

    location ~ \.php$ { 
     include snippets/fastcgi-php.conf; 
     fastcgi_pass unix:/run/php/php7.0-fpm.sock; 
    } 
} 

如果有人可以帮帮忙,这将是伟大的!

回答

0

如果你检查你的HTTP服务器的配置,你会看到一个重写规则

rewrite ^/(.*) https://www.example.com/$1 permanent; 

这基本上匹配任何给定的URL和这场比赛是继传递到新的位置作为参数$1(检查正则表达式)。

如果去掉这个参数,你应该完成你想要的:

rewrite ^/.* https://www.example.com/ permanent;