title: Wordpress Mixed Content Error, Nginx reverse proxy behind Amazon ELB
body: <p><strong>UPDATE:</strong>
  I solved the problem with the mixed content with a plugin
  The main problem now is that when I go to the admin login page I get redirected to the login page inside &lt;> instead my domain</p>
  
  <ul>
  <li><p>I have a Rails application on Amazon Elastic Beanstalk, behind an Amazon Elastic Load Balancer. 
  On the same servers as the Rails application I have a nginx server with reverse proxy to a Wordpress blog on a different server. (So it can be accessed as example.com/blog)</p></li>
  <li><p>Our domain is on GoDaddy, there I have a forwarding rule, from example.com to <a href="https://www.example.com" rel="nofollow noreferrer">https://www.example.com</a>. The domain itself is forwarded to the CNAME of the ELB</p></li>
  <li><p>On the Load Balancer there is a listener for port 443 and it's forwarded to port 80</p></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/mHRyD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mHRyD.png" alt="enter image description here"></a></p>
  
  <ul>
  <li><p>Inside the server I have a rule that is forcing a redirection from http to https</p></li>
  <li><p>When I used a single server without the Load Balancer the reverse proxy worked flawlessly, but since I started using it, the blog's assets are not loaded properly and I get the mixed content error.<a href="https://i.stack.imgur.com/2E5q1.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2E5q1.png" alt="enter image description here"></a></p></li>
  </ul>
  
  <p><strong>nginx config that works without the elb:</strong></p>
  
  <pre><code>server {
    listen 80;
    server_name &lt;&lt;rails-app-domain&gt;&gt;;
  
    if ($time_iso8601 ~ "^(d{4})-(d{2})-(d{2})T(d{2})") {
      set $year $1;
      set $month $2;
      set $day $3;
      set $hour $4;
    }
  
    access_log  /var/log/nginx/access.log  main;
    access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;
  
    location /health_check {
      access_log off;
      return 200;
    }
  
    location / {
      if ($http_x_forwarded_proto != 'https') {
        return 301 https://$server_name$request_uri;
      }
  
      proxy_pass http://my_app;
      proxy_set_header Host $host;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }
  
    location ^~ /blog {
      proxy_pass http://&lt;&lt;wordpress-server-ip&gt;&gt;/blog;
      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_redirect http://&lt;&lt;wordpress-server-ip&gt;&gt;/ https://$host/;
      proxy_cookie_domain &lt;&lt;wordpress-server-ip&gt;&gt; $host;
    }
  
    location /assets {
      alias /var/app/current/public/assets;
      gzip_static on;
      gzip on;
      expires max;
      add_header Cache-Control public;
    }
  
    location /public {
      alias /var/app/current/public;
      gzip_static on;
      gzip on;
      expires max;
      add_header Cache-Control public;
    }
  
    location /cable {
      proxy_pass http://my_app;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection "upgrade";
    }
  }
  </code></pre>
  
  <p><strong>wordpress wp-config.php:</strong></p>
  
  <pre><code>define('WP_SITEURL', 'https://&lt;&lt;rails-app-domain&gt;&gt;/blog');
  define('WP_HOME', 'https://&lt;&lt;rails-app-domain&gt;&gt;/blog');
  
  define('FORCE_SSL_ADMIN', true);
  </code></pre>
  
  <p><strong>What I tried:</strong></p>
  
  <ol>
  <li>Setting a sub filter for http -> https rewrite rule for all the
  locations inside /blog </li>
  <li>A redirect rule for all the locations inside /blog from http to https</li>
  <li><p>Adding a listener for port 443 in nginx and redirecting port
  443 of the load balancer to port 443 of the server (instead of 80
  like before)</p></li>
  <li><p>Removing the domain forwarding on GoDaddy</p></li>
  </ol>