Docker/WordPress in Sub-Path Redirects to Root

#1
I installed WordPress+OpenLiteSpeed in Docker using this script, adapting it for my needs.

I'm hosting the blog in '/blog' sub-path here.

I added this to wp-config.php

Code:
define('WP_HOME', 'https://www.shamanicattraction.com/blog/');

define('WP_SITEURL', 'https://www.shamanicattraction.com/blog/');
Home page works! Admin panel redirects to root.

The deployment finally works. Figured out I could fix the admin panel by adding this in wp-config.php

Code:
$_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);
Great, root and admin panel work... but every other page returns a 404 error by OpenLiteSpeed.

Here's my `nginx` conf file.

Code:
server {
    listen        80;
    listen        [::]:80;
    server_name   shamanicattraction.com;
    return 301 $scheme://www.shamanicattraction.com$request_uri;

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.shamanicattraction.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.shamanicattraction.com/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 {
    server_name   www.shamanicattraction.com;

    location /.well-known/acme-challenge/ {
        root /var/www/certbot;
    }

    location / {
        proxy_pass         http://127.0.0.1:5004/;
        proxy_http_version 1.1;
        proxy_set_header   Upgrade $http_upgrade;
        proxy_set_header   Connection $connection_upgrade;
        proxy_set_header   Host $host;
        proxy_cache_bypass $http_upgrade;
        proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }

    location /blog/ {
    proxy_pass         http://127.0.0.1:5080/;
        proxy_set_header   Host $host;
        proxy_set_header   X-Forwarded-Proto $scheme;
    }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/www.shamanicattraction.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/www.shamanicattraction.com/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 = www.shamanicattraction.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen        80;
    listen        [::]:80;
    server_name   www.shamanicattraction.com;
    return 404; # managed by Certbot
}
OpenLiteSpeed running in Docker on port 5080 has automatic default configuration, that's the bottom of the configuration file

Code:
vhTemplate docker {
    templateFile            conf/templates/docker.conf
    listeners               HTTP, HTTPS
    member shamanicattraction.com {
        vhDomain              shamanicattraction.com,www.shamanicattraction.com
    }
    note                    docker

    member localhost {
        vhDomain              localhost, *
    }
}
I can't figure this one out. Why does it keep redirecting to root and breaking the URLs? In Wordpress, General and Permalink tabs look OK.

I'm thinking the problem is with OpenLiteSpeed configuration because Nginx forwards the request and OpenLiteSpeed is the one throwing the 404 error.
 

Cold-Egg

Administrator
#2
I am a little bit confused, you are using nginx to serve wordpress already, so why and how to use ols-docker-env solution with the existing stack? Have you checked the .htaccess file? What's the .htaccess content?
 
#3
NGINX is on the VPS directly purely as a reverse proxy (and handling SSL certificates). OpenLiteSpeed runs WordPress in Docker.

Here's the content of .htaccess. I disabled OLS Cache plugin for now.

Code:
# BEGIN LSCACHE
# END LSCACHE
# BEGIN NON_LSCACHE
# END NON_LSCACHE
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>

# END WordPress
 
#4
I did find a solution here to host wordpress in a subfolder.

Moved all files from "html" into "html/blog/", and added this .htaccess file into "html"

Code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /blog/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ blog/index.php [L]
</IfModule>
This works for the blog content but not for the admin section!

So the other fix of adding this to wp-config.php is still required

Code:
_SERVER['REQUEST_URI'] = str_replace("/wp-admin/", "/blog/wp-admin/",  $_SERVER['REQUEST_URI']);
It feels a little bit hacky; and breaks the separation of concerns, I didn't want the docker containers to have to be concerned about where they were being displayed.

If content and admin require separate fixes; will anything else break?

Is there a better solution or that's it?

That's an old website; will soon perform the same transfer surgery on my main website.

Trying to activate OSL CDN gives this error; might be some issues with the API

Error 1110: Please verify that your other plugins are not blocking REST API calls, allowlist our server IPs, or contact your server admin for assistance.
 

Cold-Egg

Administrator
#5
I think this part is purely a WordPress configuration issue, and not caused by OpenLiteSpeed.
Here's another guide that you might want to take a look at and see if it's easier to config, https://developer.wordpress.org/adv...press-in-directory/#method-ii-with-url-change

When the first time you set up ols-docker-env, please check if you have the REST API block issue, if not, then check if there are any security plugins you have installed on the blog site that caused it.
 
#6
Following that guide is not giving me any better result, unfortunately.

At this point the only issue I have is with activating QUIC.cloud; and probably got some issue regarding the API that I'm not using otherwise. Not huge deals but still.
 
Top