By Adam Wilson
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
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!
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
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.