将www重定向到非www导致太多重定向

时间:2020-05-29 15:14:52

标签: nginx virtualhost

我的nginx中有以下虚拟配置

server {
    listen 80;
    listen [::]:80;

    root /var/www/smartpanel;
    index  index.php index.html index.htm;

    server_name www.test.com;
    return 301 http://test.com$request_uri;

    client_max_body_size 100M;

    autoindex off;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
    }


   include snippets/phpmyadmin.conf;
}

我基本上想将所有www重定向到非www,但是上面的配置只是给我来回重定向,直到chomr说

test.com redirected you too many times. 

我做错了什么?

当我执行ajax调用时,也是如此奇怪的问题。它总是给我302错误。

enter image description here

0 个答案:

没有答案