docker nginx代理:错误ERR_TOO_MANY_REDIRECTS

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

这似乎很奇怪,因为在安装过程中显然没有问题,所以我认为必须有一些我还没有得到的东西。 我认为有一些reqrite规则混淆了架构,但我无法弄清楚什么是错的。

这是我configuration的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; } } 

我将以下环境variables添加到magento docker容器中:

  • VIRTUAL_HOST example.com
  • VIRTUAL_PORT 443
  • VIRTUAL_PROTO https

此外,我将SSL证书添加到nginx代理以及magento nginxconfiguration。 所以每个容器(nginx代理和magento)都包含这个证书。

这个想法是,nginx代理通过SSL连接将example.com的所有请求转发到magento容器。

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

我已经拼命工作了几天,非常感谢任何暗示。 请问证书有问题吗? 例如,如果从nginx代理转发的请求包含不同的服务器名称,并且无法validationmagento上的证书? 但如果是这样,那怎么能解决呢?

谢谢彼得

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

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

彼得

看起来您正在使用SSL完全访问您的站点。

你有没有把你的Magento不安全的path设置为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"