douye9175 2017-03-06 13:34
浏览 99

Nginx没有将www重定向到www

So I a website which i cant reveal the url to at the moment. So i will refer to it as www.example.com for this question.

I want any attempt to get to my site to redirect to HTTPS:://www.example.com. However this is not the case. I have managed to get it working with redirecting http to https.

If i go to example.com it does redirect to www.example.com, but if i try any other route such as example.com/videos it just redirects to https://example.com/videos instead of https://www.example.com.

Here is my nginx config file:

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

If anyone could help out that would be great!

  • 写回答

1条回答

  • duanji1026 2017-03-06 14:33
    关注

    If you check your HTTP server configuration you should see a rewrite rule

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

    This basically matches any given URL and this match is afterwards passed to the new location as the parameter $1 (check regular expressions).

    If you remove this parameter, you should accomplish what you want:

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

报告相同问题?

悬赏问题

  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法