docker nginx 代理:错误 ERR_TOO_MANY_REDIRECTS

docker nginx 代理:错误 ERR_TOO_MANY_REDIRECTS

我正在使用 jwilder/nginx-proxy docker 容器通过 SSL 代理 magento 容器(使用 nginx)。我能够设置容器并使用 SSL 连接运行 magento 安装程序。完成安装后,每当我尝试访问 magento 前端或后端时,都会收到 ERR_TOO_MANY_REDIRECTS 错误消息。

这似乎很奇怪,因为安装过程中显然没有问题,所以我猜想肯定是有些东西我还没有得到。我猜想是有一些 reqrite 规则搞乱了架构,但我搞不清楚到底出了什么问题。

这是我的 magento nginx 配置:

#
# The default server
#
server {

listen   443;

ssl on;

server_name example.com;

ssl_certificate        /etc/certs/example.com.crt;
ssl_certificate_key    /etc/certs/example.com.key;

#charset koi8-r;


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


location / {

    index index.html index.php; ## Allow a static html file to be shown first

    try_files $uri $uri/ @handler; ## If missing pass the URI to Magento's front handler

    expires 30d; ## Assume all files are cachable

}



## These locations would be hidden by .htaccess normally

location ^~ /app/                { deny all; }

location ^~ /includes/           { deny all; }

location ^~ /lib/                { deny all; }

location ^~ /media/downloadable/ { deny all; }

location ^~ /pkginfo/            { deny all; }

location ^~ /report/config.xml   { deny all; }

location ^~ /var/                { deny all; }



location /var/export/ { ## Allow admins only to view export folder

    auth_basic           "Restricted"; ## Message shown in login window

    auth_basic_user_file htpasswd; ## See /etc/nginx/htpassword

    autoindex            on;

}



location  /. { ## Disable .htaccess and other hidden files

    return 404;

}



location @handler { ## Magento uses a common front handler

    rewrite / /index.php;

}



location ~ .php/ { ## Forward paths like /js/index.php/x.js to relevant handler

    rewrite ^(.*.php)/ $1 last;

    fastcgi_read_timeout 500;

}


# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

}

我向 magento docker 容器添加了以下环境变量:

  • VIRTUAL_HOST example.com
  • 虚拟端口 443
  • 虚拟协议 https

此外,我还将 SSL 证书添加到 nginx 代理以及 magento nginx 配置中。因此每个容器(nginx 代理和 magento)都包含此证书。

其理念是 nginx 代理通过 SSL 连接将来自 example.com 的所有请求转发到 magento 容器。

magento 容器不向公众公开任何端口,但 nginx 代理链接到容器(出于安全原因)。

我已经为此努力了好几天,非常感谢任何提示。证书可能存在问题吗?例如,如果来自 nginx 代理的转发请求包含不同的服务器名称,并且无法使用 magento 上的证书进行验证?!但如果是这样,该如何解决?

谢谢彼得

答案1

在您的 Magento 2.x 安装目录中执行此操作,您的网站将恢复正常(具有安全连接)。

sudo php bin/magento setup:store-config:set --base-url-secure="https://example.com"

答案2

彼得

看起来您正在使您的网站完全可以通过 SSL 访问。

您是否已将 Magento 中的不安全路径设置为 https?对于基本的 Magento 安装,这可能就是您所需要的?

update core_config_data set value="https://<mysite>/" where path="web/unsecure/base_url"

此外你可能还需要

update core_config_data set value=1 where path="web/secure/use_in_adminhtml"

相关内容