title: How to solve ERR_INVALID_REDIRECT for an HTTPS Wordpress website on Apache behind Nginx and varnish?
body: <p>My website home page returns &quot;ERR_INVALID_REDIRECT&quot;. All the other pages of the website are fine. It just returns this issue for the Homepage (meaning: <a href="https://www.mywebsiteurl.com/" rel="nofollow noreferrer">https://www.mywebsiteurl.com/</a>).</p>
  <p>The reason is that Wordpress decides to redirect to &quot;https:///&quot; (cf. screenshot below: X-redirect-by: Wordpress)</p>
  <p><a href="https://i.stack.imgur.com/WpNpG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WpNpG.png" alt="enter image description here" /></a></p>
  <p>I have already:</p>
  <ul>
  <li>Cleared my browser cache</li>
  <li>Restarted Nginx, Varnish and Apache</li>
  <li>Deactivated the plugins from wordpress</li>
  <li>in my wp-config.php file the WP_HOME and WP_SITEURL are set properly.</li>
  </ul>
  <p>I did just upgraded to Wordpress: 5.6.1 and also updated my Theme yesterday. There was no problem before the upgrade. So the problem is certainly coming from one of these actions.</p>
  <p>My question is, What else should I check?
  What are the next actions that I could take the figure out where the problem comes from? Any advanced debugging I could do somehow?</p>
  <p>Thanks a lot.</p>
  <p>UPDATE #1</p>
  <p>Mywebsite.conf</p>
  <pre><code>&lt;VirtualHost *:8080&gt;
     ServerName www.mywebsite.com
     DocumentRoot /var/www/wordpress/
  
     LogFormat &quot;%{X-Forwarded-For}i %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{User-agent}i\&quot;&quot; varnishcombined
     ErrorLog /var/log/apache2/wordpress/mywebsite-error.log
     CustomLog /var/log/apache2/wordpress/mywebsite-access.log varnishcombined
  
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>wordpress.conf</p>
  <pre><code>&lt;Directory /var/www/wordpress/&gt;
       Options Indexes FollowSymLinks
       AllowOverride All
       Require all granted
  &lt;/Directory&gt;
  &lt;VirtualHost *:80&gt;
       ServerName 139.162.xx.xx #I masked the IP here
       #Redirect permanent / http://www.mywebsite.com/
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/wordpress/
       ErrorLog /var/log/apache2/wordpress/error.log
       CustomLog /var/log/apache2/wordpress/access.log combined
       &lt;files xmlrpc.php&gt;
         order allow,deny
         deny from all 
       &lt;/files&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  <p>The last virtual host from wordpress.com should not be taken in to account because Apache just listens on port 8080.
  Nginx, my front webserver listens on port 80 and 443.</p>
  <p>UPDATE #2</p>
  <p>mywebsite.conf (Nginx conf)</p>
  <pre><code>server {
    listen 443;
    server_name www.mywebsite.com;
    port_in_redirect off;
  
    ssl on;
    ssl_certificate /etc/ssl/private/mywebsite.com.chained.crt;
    ssl_certificate_key /etc/ssl/private/mywebsite_com_key.txt;
  
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!dSS;
    ssl_prefer_server_ciphers   on;
  
    ssl_session_cache   shared:SSL:20m;
    ssl_session_timeout 60m;
  
    add_header Strict-Transport-Security &quot;max-age=31536000&quot;;
    add_header X-Content-Type-Options nosniff;
  
    location / {
  
       proxy_pass            http://127.0.0.1:6081;
       proxy_read_timeout    90;
       proxy_redirect        off;
  
  
       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 https;
       proxy_set_header      X-Forwarded-Port 443;
       proxy_set_header      Host $host;
       proxy_set_header      X-Forwarded-Host $http_host;
       proxy_set_header      HTTPS &quot;on&quot;;
     }
  }
  
  server {
     listen 443 ssl;
     server_name mywebsite.com;
  
     return 301 https://www.mywebsite.com$request_uri;
  }
  
  server {
     listen 80 default_server;
     server_name _;
     return 301 https://$host$request_uri;
  }
  </code></pre>
  <p>UPDATE #3</p>
  <pre><code> #curl -v -H 'Host: www.mywebsite.com' http://127.0.0.1:8080/
   * Expire in 0 ms for 6 (transfer 0x56356f708f50)
   *   Trying 127.0.0.1...
   * TCP_NODELAY set
   * Expire in 200 ms for 4 (transfer 0x56356f708f50)
   * Connected to 127.0.0.1 (127.0.0.1) port 8080 (#0)
   &gt; GET / HTTP/1.1
   &gt; Host: www.mywebsite.com
   &gt; User-Agent: curl/7.64.0
   &gt; Accept: */*
   &gt; 
   &lt; HTTP/1.1 301 Moved Permanently
   &lt; Date: Wed, 24 Feb 2021 14:32:06 GMT
   &lt; Server: Apache/2.4.38 (Debian)
   &lt; X-Redirect-By: WordPress
   &lt; Location: https://www.mywebsite.com/
   &lt; Content-Length: 0
   &lt; Content-Type: text/html; charset=UTF-8
   &lt; 
   * Connection #0 to host 127.0.0.1 left intact
  </code></pre>