0

I have a wordpress site with nginx packed into a Docker image behind an AWS ELB Load Balancer. Only HTTPS is enabled on the load balancer.

When I access the URL: https://example.com/wp-admin/ it works fine but when I access the URL:

https://example.com/wp-admin the server fails as it tries to redirect to url: http://example.com/wp-admin/

I found this thread which has similar issue and applies all three possible solution options suggested but it didn't workout for me.

Here is my nginx config file for the site

How do I prevent the HTTPS to HTTP redirect or redirect from HTTPS to HTTPS e.g: https://example.com/wp-admin to https://example.com/wp-admin/

My wp-config.php

12
  • I might be missing something but after reading your config files I cannot see where Nginx is handling https at all. Do you have another config including https, it is more likely that is where the issue is because it redirects from https to http. Commented Sep 7, 2020 at 8:47
  • Oh wait, I've also just seen the proxy_pass statement. Is Nginx acting as a reverse proxy? Commented Sep 7, 2020 at 8:49
  • Yes. And https is being handeled by aws elb. Commented Sep 7, 2020 at 8:51
  • You explicitly redirect to http with: rewrite /wp-admin$ $scheme://$host$uri/ permanent; - that statement is not necessary as the try_files should perform that function for you anyway. Commented Sep 7, 2020 at 8:52
  • @RichardSmith thank you very much for pointing it out for me. Sure I'll make the changes. Commented Sep 7, 2020 at 8:54

1 Answer 1

0

Adding:

absolute_redirect off; if ($http_x_forwarded_proto = "http") { return 301 https://$host$request_uri; } 

in my nginx config file for the site solved the issue for me.

1
  • Good to know what sorted it out. You can click the up-arrow to mark it as the accepted & correct answer. Commented Sep 15, 2020 at 22:27

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.