0

We receive error about "redirected you too many times." after changing the Wordpress from HTTP to HTTPS. The WP is on AWS with Nginx and we have tried changing both define(home) and define(siteurl) in both database and wp-config file but no help.

Below is the current nginx config file, we also tried following some posts on Google to change HTTP to HTTPS, listening port to 443 but still no luck.

Thanks in advance.

server { listen 443; server_name wp.mywebsite.com; server_name www.mywp.mywebsite.com; include /etc/nginx/common_server_settings; location /wp-content/ { root /var/www/mywp.mywebsite.com; } location /wp-includes/ { root /var/www/mywp.mywebsite.com; } set $no_cache 0; # POST requests should always go to PHP if ($request_method = POST) { set $no_cache 1; } # Don't cache uris containing the following segments if ($request_uri ~* "(/wp-admin/|/xmlrpc.php|/wp-(app|cron|login|register|mail).php|wp-.*.php|/feed/|index.php|wp-comments-popup.php|wp-links-opml.php|wp-locations.php|sitemap(_index)?.xml|[a-z0-9_-]+-sitemap([0-9]+)?.xml)") { set $no_cache 1; } # Don't use the cache for logged in users or recent commenters if ($http_cookie ~* "comment_author|wordpress_[a-f0-9]+|wp-postpass|wordpress_logged_in") { set $no_cache 1; } location / { proxy_http_version 1.1; proxy_set_header Host $http_host; #proxy_set_header Host "mywp.mywebsite.com"; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto http; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_hide_header X-Powered-By; proxy_pass http://127.0.0.1:1080; proxy_cache_bypass $no_cache; proxy_no_cache $no_cache; proxy_cache_lock on; proxy_cache BLOG; proxy_cache_valid 5m; add_header X-Raw $no_cache; } } 

2 Answers 2

1

proxy_set_header X-Forwarded-Proto http;

The headers are causing this redirect loop since the wordpress still thinks that it is being accessed using "http" scheme (because your reverse proxy server is not sending the correct scheme in the header.

It may be also possible that you need to make a change in wordpress config file so that it correctly detects the HTTPS. As described here:

Websites behind load balancers or reverse proxies that support HTTP_X_FORWARDED_PROTO can be fixed by adding the following code to the wp-config.php file, above the require_once call:

if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS'] = 'on'; 
Sign up to request clarification or add additional context in comments.

Comments

0

I use this type of config for proxying to https:

server { listen 443 ssl; server_name wp.mywebsite.com; server_tokens off; ssl on; ssl_certificate /etc/nginx/ssl/cert.crt; ssl_certificate_key /etc/nginx/ssl/cert.key; ssl_protocols SSLv3 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; set $ssl off; etag on; if ($scheme = https) { set $ssl on; } location / { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Forwarded-Ssl $ssl; proxy_pass http://127.0.0.1:1080; proxy_read_timeout 90; proxy_redirect http://127.0.0.1:1080 wp.mywebsite.com; } } 

Also don't forget to force https:

server { server_tokens off; listen 80; server_name wp.mywebsite.com; return 301 https://wp.mywebsite.com$request_uri; } 

1 Comment

Hi vhoxsha, thank you for the feedback however our site is using section.io SSL, do you know how to include it in the file?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.