4

UPDATE: 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 <> instead my domain

  • 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)

  • Our domain is on GoDaddy, there I have a forwarding rule, from example.com to https://www.example.com. The domain itself is forwarded to the CNAME of the ELB

  • On the Load Balancer there is a listener for port 443 and it's forwarded to port 80

enter image description here

  • Inside the server I have a rule that is forcing a redirection from http to https

  • 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.enter image description here

nginx config that works without the elb:

server {
  listen 80;
  server_name <<rails-app-domain>>;

  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://<<wordpress-server-ip>>/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://<<wordpress-server-ip>>/ https://$host/;
    proxy_cookie_domain <<wordpress-server-ip>> $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";
  }
}

wordpress wp-config.php:

define('WP_SITEURL', 'https://<<rails-app-domain>>/blog');
define('WP_HOME', 'https://<<rails-app-domain>>/blog');

define('FORCE_SSL_ADMIN', true);

What I tried:

  1. Setting a sub filter for http -> https rewrite rule for all the locations inside /blog
  2. A redirect rule for all the locations inside /blog from http to https
  3. 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)

  4. Removing the domain forwarding on GoDaddy

Max Dubinin
  • 214
  • 3
  • 20
  • In your Wordpress settings, what are your `Wordpress Address` and `Site Address` set to? Are they set to `https`? – Mark B Nov 01 '17 at 15:20
  • @MarkB Yes. I added it also to the question now – Max Dubinin Nov 01 '17 at 15:22
  • @MaxDBN, see if this helps https://stackoverflow.com/questions/46080660/nginx-reverse-proxy-from-rails-to-wordpress/46093134#46093134 – Tarun Lalwani Nov 01 '17 at 16:34
  • @TarunLalwani Hey Tarun, this is my old thread :) No it doesn't help. It works great with one instance but for some reason not with a load balancer – Max Dubinin Nov 02 '17 at 08:02
  • @MaxDBN, lol. Will see what could be the issue – Tarun Lalwani Nov 02 '17 at 08:08
  • @TarunLalwani I added a plugin that forces https on assets but it not works for JS (I'll deal with it later). The problem is that when I go to the admin login page it redirects to the wordpress IP instead of the domain. – Max Dubinin Nov 02 '17 at 11:01

0 Answers0