【问题标题】:nginx endless redirection (not the SSL bug)nginx 无限重定向(不是 SSL 错误)
【发布时间】:2013-05-24 07:56:27
【问题描述】:

编辑:问题是,我无法弄清楚我使用的是子域,我尝试只使用我的 TLD(纯)my.de 进行配置,瞧,它开箱即用.关于如何解决这个问题的任何想法?

我目前正在使用此 nginx 配置在 Ubuntu 12.xx (VPS) 上的 nginx 1.3.x 上的 FastCGI (PHP-FPM) 上运行 OpenCart (v1.5.5.1) (PHP)。

当我尝试访问安装文件夹中的 index.php 时,如下所述:http://docs.opencart.com/display/opencart/Installation 我最终陷入了无休止的重定向循环:

shop.mysite.com/install/shop.mysite.com/shop.mysite.com/.........etc/index.php

访问日志没有显示任何有用的信息,错误日志也没有显示任何内容。

# FORCE WWW
server {
    server_name  .shop.my.de;
    rewrite ^(.*) .shop.my.de$1 permanent;
}
# MAIN SERVER
server {
    error_log    /var/log/nginx/shop.my.de.error.log debug;
    access_log  /var/log/nginx/shop.my.de.access.log;
    server_name  .shop.my.de;
    listen 80;
    root /srv/opencart/upload;
    index index.php;

    location /install {
        index index.php;
    }
    location /image/data {
        autoindex on;
    }
    location /admin {
        index index.php;
    }
    location / {
        try_files $uri @opencart;
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    location = /favicon.ico {
        log_not_found off;
        #access_log off;
    }
    location = /robots.txt {
        allow all;
        #log_not_found off;
        #access_log off;
    }
    # Make sure files with the following extensions do not get loaded by nginx because nginx would display the source code, and these files can contain PASSWORDS!
    location ~* \.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|\.php_ {
        deny all;
    }
    # Deny all attempts to access hidden files such as .htaccess, .htpasswd, .DS_Store (Mac).
    location ~ /\. {
        deny all;
        #access_log off;
        #log_not_found off;
    }
    location ~*  \.(jpg|jpeg|png|gif|css|js|ico)$ {
        expires max;
        #log_not_found off;
    }
    location ~ \.php$ {
        try_files $uri =404;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

【问题讨论】:

  • 如果禁用重写会发生什么?您运行的是什么版本的 OpenCart?
  • Opencart 1.5.5.1,我禁用了一些重写(最上面的)并没有改变。任何其他重写对于确保 OpenCart 正常工作都是至关重要的。
  • 特别是_route_ 我建议尝试一下。至于无限重定向 - 安装步骤 1 没有任何重定向(index.php 引导程序也没有,所以它不会是那些)
  • 这条线怎么样?这似乎是诚实的location /install { index index.php; } 它基本上说使用opencart index.php 文件而不是/install/index.php - 编辑:忽略这一点,我误读了命令。老实说,我不确定。我建议你删除所有不是绝对需要的东西,看看它是否有效 - 然后开始一次添加一行
  • 非常奇怪。有一件事是肯定的——这是一个 NGINX 问题,而不是 OpenCart 问题,所以你需要从有 nginx 经验的人那里得到答案(恐怕我没有)

标签: php nginx opencart fastcgi


【解决方案1】:

解决方案是如果您想在子域上使用 NGINX + Opencart: 如果你不这样做,opencart 会在重定向之间疯狂地反弹。

server {
    server_name  .shop.my.de;
    rewrite ^(.*) www.shop.my.de$1 permanent; # the www is the important thing!!
}

和

server {
    #..........
    server_name  www.shop.my.de; # also HERE! www is the important thing
    #..........
}

【讨论】:

    猜你喜欢
    • 2012-06-17
    • 1970-01-01
    • 2016-12-18
    • 2017-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-25
    • 2017-11-09
    相关资源
    最近更新 更多