3

I have a setup where Apache listens on port 8080 behind Varnish 4 on port 80, but my client needs ssl working on the site so I setup Nginx for SSL termination on port 443 using this guide.

Everything works fine at first on http, but on attempting to load the site on https, scripts required by the site won't load, So I decided to change the site url in Settings > General to an https url, on saving changes, I get a redirect loop error in Chrome.

I couldn't access the site's wordpress dashboard to change the url back so I had to do it via phpmyadmin. But now when the site is accessed via https, the site breaks cause the scripts it requires to render content aren't authenticated.

Someone else has the same issue here but it doesn't look like it was solved.

How can I have the site on just https without a redirect loop in Chrome?

2 Answers 2

13

After hours of trying to get this to work, I finally found a fix, all I had to was add an HTTP_X_FORWARDED_PROTO in my wp-config.php just before changing the site url, this way:

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

One more thing I had to do was to add proxy_set_header X-Forwarded-Protocol $scheme; to my default file in /etc/nginx/sites-enabled/default so it looks like this:

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

Hope this helps someone out there.

Sign up to request clarification or add additional context in comments.

2 Comments

Man! You are just awesome.... This saved me hours of work... You are the man!!!! Thanks a ton!
This was very helpful! I had to change proxy_set_header X-Forwarded-Protocol $scheme; toproxy_set_header X-Forwarded-Proto $scheme; The header that nginx passes needs to match what the wp-config.php file is looking for
2

You can set this header in nginx:

proxy_set_header X-Forwarded-Proto $scheme;

and then in your apache vhost configuration:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.