Prestashop 1.7 前端商店重定向过多

Prestashop 1.7 前端商店重定向过多

尝试导航到 Prestashop 1.7 网站的前端商店时,我不断收到 ERR_TOO_MANY_REDIRECTS。但是,转到管理后端时一切正常。

任何的意见都将会有帮助。

网站使用 Nginx、PHP-FPM7、MariaDB 运行。

Nginx 配置文件如下:

upstream examplecoukbackend {
        server unix:/var/run/php-fcgi-examplecouk.sock;
}

server {
        listen 80;
        server_name example.co.uk;
        return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;

    ssl_session_timeout 24h;
    ssl_session_cache shared:SSL:10m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:RSA+3DES:AES128-SHA:!ADH:!AECDH:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_certificate /etc/letsencrypt/live/example.co.uk/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.co.uk/privkey.pem;

    server_name example.co.uk;
    root /var/www/vhosts/example.co.uk/htdocs; 
    access_log /var/www/vhosts/example.co.uk/access.log;
    error_log /var/www/vhosts/example.co.uk/error.log;

    index index.php index.html;

    location = /favicon.ico {
        log_not_found off;
        access_log off;
    }

    location = /robots.txt {
        auth_basic off;
        allow all;
        log_not_found off;
        access_log off;
    }

    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        access_log off;
        log_not_found off;
    }

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 1;
    gzip_buffers 16 8k;
    gzip_http_version 1.0;
    gzip_types application/json text/css application/javascript;

    rewrite ^/[a-zA-Z][a-zA-Z]/(index\.php.*)$ /$1 last;  #Remove language code when index.php is called directly
    rewrite ^/api/?(.*)$ /webservice/dispatcher.php?url=$1 last;
    rewrite ^/([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$1$2$3.jpg last;
    rewrite ^/([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$1$2$3$4.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$1$2$3$4$5.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$1$2$3$4$5$6.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$1$2$3$4$5$6$7.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$1$2$3$4$5$6$7$8.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$1$2$3$4$5$6$7$8$9.jpg last;
    rewrite ^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-]*)?(-[0-9]+)?/.+.jpg$ /img/p/$1/$2/$3/$4/$5/$6/$7/$8/$1$2$3$4$5$6$7$8$9$10.jpg last;
    rewrite ^/c/([0-9]+)(-[.*_a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$ /img/c/$1$2$3.jpg last;
    rewrite ^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$ /img/c/$1$2.jpg last;

    location /admin/ {                           #Change this to your admin folder
        if (!-e $request_filename) {
            rewrite ^/.*$ /admin/index.php last; #Change this to your admin folder
        }
    }

    location / {
        if (!-e $request_filename) {
            rewrite ^/.*$ /index.php last;
        }
    }

    location ~ .php$ {
        fastcgi_split_path_info ^(.+.php)(/.*)$;
        try_files $uri =404;
        fastcgi_keep_conn on;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass examplecoukbackend;  #Change this to your PHP-FPM location
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

以下是日志文件、IP 和域名概述:

2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 "^/([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])([0-9])(-[_a-zA-Z0-9-])?(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:1 “^/c/([0-9]+)(-[._a-zA-Z0-9-]*)(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk” 2017/01/08 21:58:00 [通知] 21867#21867:*1 "^/c/([a-zA-Z_-]+)(-[0-9]+)?/.+.jpg$" 与 "/index.php" 不匹配,客户端:0.0.0.0,服务器:example.co.uk,请求:“GET /index.php HTTP/1.1”,主机:“example.co.uk”

答案1

这里有一个问题是这个块:

location / {
    if (!-e $request_filename) {
        rewrite ^/.*$ /index.php last;
    }
}

应该使用这个:

try_files $uri $uri/ /index.php;

然后对于你的管理员:

location /admin/ {                           #Change this to your admin folder
    if (!-e $request_filename) {
        rewrite ^/.*$ /admin/index.php last; #Change this to your admin folder
    }
}

你可以使用这个:

location /admin/ {
    try_files $uri $uri/ /admin/index.php;
}

然而,这些变化可能无法解决您的问题。

答案2

最有可能的是Prestashop 中的主 URL配置错误。

来自文档:

  • 主要网址。启用此功能,即表示您希望此商店的所有其他 URL 重定向到此主 URL

如果您http://example.com在 Prestashop 中配置,但配置 nginx 将所有 HTTP 请求重定向到 HTTPS,您将得到这样的重定向循环。

确保将 Prestashop 中的主 URL 配置为您的 httpd 重定向到的 URL。

答案3

如果你只在商店前面遇到此问题,那么你应该转到设置 URL->重定向到规范 URL,并将其设置为无重定向

答案4

当我将 Prestashop 从本地移至在线时,我遇到了同样的问题。我通过删除解决了这个问题。.htaccess 文件的所有内容。我认为问题是由于 .htaccess 和 nginx 配置中的重写规则之间存在冲突而引起的。

我使用这个 nginx.confhttps://github.com/PrestaShop/docs/blob/master/nginx.rst并删除 .htaccess 的内容。301 HTTP 错误就消失了。

相关内容