Question

Redirecting to Wordpress site from Rails app

I have a Rails app, and I’m trying to set up a redirect for all URLs after /content/ to go to a Wordpress installation on another server.

Following [this Stack Overflow answer],(https://stackoverflow.com/a/46096834/862106) I currently have the following in my nginx config:

upstream puma {
  server unix:///home/deploy/my-website/shared/tmp/sockets/entonal-website-puma.sock;
}

server {
  server_name my.domain;

  root /home/deploy/my-website/current/public;
  access_log /home/deploy/my-website/current/log/nginx.access.log;
  error_log /home/deploy/my-website/current/log/nginx.error.log info;

  location ^~ /assets/ {
    gzip_static on;
    expires max;
    add_header Cache-Control public;
  }

  location ^~ /content {
      proxy_pass http://<Wordpress-IP>/content;
      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-IP>/ https://$host/;
      proxy_cookie_domain <Wordpress-IP> $host;
    }

  try_files $uri/index.html $uri @puma;
  location @puma {
    proxy_set_header  Host $host;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header  X-Forwarded-Proto $scheme;
    # proxy_set_header  X-Forwarded-Ssl on;
    proxy_set_header  X-Forwarded-Port $server_port;
    proxy_set_header  X-Forwarded-Host $host;

    proxy_pass http://puma;
  }

  error_page 500 502 503 504 /500.html;
  client_max_body_size 180M;
  keepalive_timeout 10;

  listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/my.domain/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my.domain/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}


server {
  if ($host = my.domain) {
    return 301 https://$host$request_uri;
  } # managed by Certbot


  listen 80 default_server deferred;
  server_name my.domain;
  return 404; # managed by Certbot
}

And this in my wp-config.php:

define('FORCE_SSL_ADMIN', true);

if ( isset( $_SERVER['HTTP_X_FORWARDED_PROTO'] ) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
    $_SERVER['HTTPS']='on';

define('WP_SITEURL', 'https://my.domain/content');
define('WP_HOME', 'https://my.domain/content');

I can see there is a redirect happening, but it does not seem to be getting picked up. When navigating to https://my.domain/content I get:

Not Found

The requested URL was not found on this server.

Apache/2.4.41 (Ubuntu) Server at $domain Port 80


Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

alexdo
Site Moderator
Site Moderator badge
November 30, 2022

Hello there,

From the looks of it, Apache is listening on port 80 and it’s not unable to server the domain name - my.domain loaded on port 80.

You can double-check the Apache settings if everything is configured properly.

Regards

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

card icon
Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Sign up
card icon
Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We’d like to help.

Learn more
card icon
Become a contributor

You get paid; we donate to tech nonprofits.

Learn more
Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow – whether you’re running one virtual machine or ten thousand.

Learn more ->
DigitalOcean Cloud Control Panel
Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.

This promotional offer applies to new account only.

© 2023 DigitalOcean, LLC.