Nginx SSL termination loop forwarding via Varnish / Apache to Wordpress

I have a setup where Apache is listening on port 8080 behind Varnish 4 on port 80, but my client needs ssl running on the site, so I install Nginx to terminate SSL on port 443 using this tutorial .

Everything works fine at first on http, but when I try to load the site on https, the scripts required by the site won't load, so I decided to change the site Settings > General

's url in to https-url, when I save the change, I get the redirect loop error in Chrome.

I couldn't access the Wordpress Word bar to change the url, so I had to do it through phpmyadmin. But now, when the site is accessed via https, the site breaks because the scripts it requires to render the content are not authenticated.

Someone else has the same problem here , but it doesn't look like it has been solved.

How can I host a site only https

without a redirect loop in Chrome?

+3


source to share


2 answers


After several attempts to get this to work, I finally found a fix, all I needed to add HTTP_X_FORWARDED_PROTO

to mine wp-config.php

just before changing the site url was like this:

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
     $_SERVER['HTTPS']='on';

      

Another thing I had to do was add proxy_set_header X-Forwarded-Protocol $scheme;

to my default

file in /etc/nginx/sites-enabled/default

so that it looks like this:



server {                                                      
        ...                                                    
        location / {                                          
                 ...
            proxy_set_header X-Forwarded-Protocol $scheme;
          }
  }

      

Hope it helps someone out there.

+7


source


You can set this header in nginx:

proxy_set_header X-Forwarded-Proto $scheme;

      



and then in your Apache vhost config:

SetEnvIf X-Forwarded-Proto "^https$" HTTPS=on

      

+1


source







All Articles