2017-04-03 26 views
4

我正在嘗試爲Prestashop項目創建一個docker環境。我有它幾乎工作,但由於某種原因,後臺無法訪問 - 它給了我一個ERR_TOO_MANY_REDIRECTS錯誤。在Docker中運行Prestashop時ERR_TOO_MANY_REDIRECTS

我更改了shop_url表中的網址,並將PS_SHOP_DOMAIN和PS_SHOP_DOMAIN_SSL更改爲無效。我試圖禁用友好的URL,啓用/禁用SSL - 但問題依然存在。

我使用的自定義圖像的web服務器:

luken-wodby-nginx-prestashop Dockerfile:

FROM wodby/nginx:1.10 

ENV WODBY_DIR_FILES /mnt/files 

RUN rm /etc/gotpl/default-vhost.conf.tpl && \ 
    mkdir -p $WODBY_DIR_FILES && \ 
    mkdir -p /var/log/nginx 

COPY prestashop.conf.tpl /etc/gotpl/ 
COPY init/* /docker-entrypoint-init.d/ 

泊塢窗,compose.yml:

version: "2" 

services: 
    mariadb: 
    image: wodby/mariadb:10.1-2.0.0 
    environment: 
     MYSQL_ROOT_PASSWORD: password 
     MYSQL_DATABASE: organic 
     MYSQL_USER: prestashop 
     MYSQL_PASSWORD: prestashop 
    volumes: 
     - ./database:/docker-entrypoint-initdb.d 
    ports: 
     - "33060:3306" 

    php: 
    image: wodby/php:5.6-2.0.0 
    environment: 
     PHP_SENDMAIL_PATH: /usr/sbin/sendmail -t -i -S mailhog:1025 
     PHP_XDEBUG: 1 
     PHP_XDEBUG_DEFAULT_ENABLE: 1 
    volumes: 
     - ./:/var/www/html 

    nginx: 
    image: luken-wodby-nginx-prestashop:latest 
    depends_on: 
     - php 
    environment: 
     NGINX_BACKEND_HOST: php 
     NGINX_SERVER_NAME: prestashop.docker.localhost 
     NGINX_SERVER_ROOT: /var/www/html/public_html 
    volumes: 
     - ./:/var/www/html 
    ports: 
     - "8000:80" 

    mailhog: 
    image: mailhog/mailhog 
    ports: 
     - "8002:8025" 

的Nginx虛擬主機配置:

server { 
    listen 80; 
    server_name {{ getenv "NGINX_SERVER_NAME" "prestashop" }}; 
    root {{ getenv "NGINX_SERVER_ROOT" "/var/www/html/" }}; 
    access_log /var/log/nginx/access.log; 
    error_log /var/log/nginx/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 ^/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; 
    rewrite ^/images_ie/?([^/]+).(jpe?g|png|gif)$ /js/jquery/plugins/fancybox/images/$1.$2 last; 
    rewrite ^/order$ /index.php?controller=order last; 
    location /panel_adm/ {       #Change this to your admin folder 
     if (!-e $request_filename) { 
      rewrite ^/.*$ /panel_adm/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 backend; #Change this to your PHP-FPM location 
     fastcgi_index index.php; 
     fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 
    } 
} 

網站工作正常,只有後臺無法訪問,並提供ERR_TOO_MANY_REDIRECTS錯誤。

任何想法可能是錯的?

回答

1

我發現這個問題的原因。 wodby/nginx nginx容器正在使用自定義的fastcgi_params文件。這個文件奇怪地沒有fastcgi_param QUERY_STRING $query_string;行(與nginx自帶的原始文件相反)。這使得它在默認情況下與您可以在Internet上找到的一些準備好的nginx模板不兼容。它表現爲查詢參數沒有傳遞給腳本(我在這裏創建了一個問題:https://github.com/wodby/nginx/issues/3)。

現在,Prestashop的後臺沒有重要的controller參數,因爲它不知道要運行哪個控制器。如果沒有控制器,它將使用默認控制器作爲參數重定向URL,但由於Prestashop中沒有可用的「控制器」參數,所以它會在重定向循環中結束,從而導致ERR_TOO_MANY_REDIRECTS

解決方法是在您的nginx配置中添加fastcgi_param QUERY_STRING $query_string;以將查詢參數傳遞給腳本。

1

據我記得,在安裝時,Prestashop需要具有完整的文件夾權限,但它會導致類似的問題。

因此,例如:

chmod 777 -R /var/www/html 

應該做的工作

+0

不幸的是,它並沒有幫助:(。 –