0

I am using the jwilder/nginx-proxy docker container to proxy a magento container (using nginx) with SSL. I was able to set up the containers and run the magento installation routine with an SSL connection. After completing the installation I get a ERR_TOO_MANY_REDIRECTS error message whenever I try to acccess the magento frontend or backend.

This seems to be weird since there is obviously no problem during installation, so I assume there must be something I am not getting yet. I assume that there are some reqrite rules which mess up the architecture, but I cannot figure out what's wrong.

This is my configuration of the 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;
}

}

I added the following evironment variables to the magento docker container:

  • VIRTUAL_HOST example.com
  • VIRTUAL_PORT 443
  • VIRTUAL_PROTO https

Furthermore I added the ssl certificates to the nginx proxy as well as to the magento nginx configuration. So each container (nginx proxy and magento) contain this certificates.

The idea is that the nginx proxy forwards all requests from example.com to the magento container via an SSL connection.

The magento container does not expose any ports to the public but the nginx proxy links to the container (for security reasons).

I have been desperately working on this for several days now and greatly appreciate any hint. Could there be any issue with the certificates? E.g. if the forwarded request from the nginx proxy coontains a different server name and there cannot verify with the certificates on magento?! But if so, how could that be resolved?

Thanks Peter

  • You forgot to post your nginx-proxy configuration! – Michael Hampton Nov 1 '15 at 16:49
  • I used the standard configuration of nginx as in github.com/jwilder/nginx-proxy without any changes – user3868893 Nov 1 '15 at 22:40
  • Did you ever solve this issue? I have the exact same setup under Docker with nginx and magento. – Darryl Jul 9 '16 at 20:56
  • yes, we resolved this issue by now: you need to add the following configuration to your nginx proxy: proxy_set_header X-Forwarded-Proto https; -> for SSL endpoint termination in your magento nginx: fastcgi_param HTTPS on; -> to prevent errors while you would loading assets via HTTP while you establish an HTTPS connection – user3868893 Jul 11 '16 at 6:29
  • Thanks! I came to the same conclusion and just now saw your answer, so it was good to see. Seems like this should be part of the jwilder/nginx-proxy instructions - I think I'll suggest it. – Darryl Jul 11 '16 at 19:51
2

Execute this in your Magento 2.x installation directory and your site will be back to normal (with secure connection).

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

Peter

Looks like you are making your site accessible with SSL completely.

Have you set your unsecure path in Magento to https? For a basic Magento install this might be all you need?

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

In addition you may also need

update core_config_data set value=1 where path="web/secure/use_in_adminhtml"
  • Unfortunately this did not resolve the issue. I am still getting "too many redirects" after having installed magento. Any have really no idea what to do try next, any hints? – user3868893 Nov 16 '15 at 6:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.