0

i'm trying to setup a kubernetes deployment for two wordpress websites in different pods, each will have it's own deployment and service, etc..., under the same ingress, i have setup the ingress this way :

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    cert-manager.io/cluster-issuer: letsencrypt
    nginx.ingress.kubernetes.io/rewrite-target: /$1
    nginx.ingress.kubernetes.io/use-regex: "true"
  labels:
    app: app-1
    built-by: kustomize
  name: app-1
  namespace: namespace-1
spec:
  ingressClassName: nginx
  rules:
- host: test.sub.website.com
    http:
      paths:
      - backend:
          service:
            name: wordpress-service-1
            port:
              number: 80
        path: /(.*)
        pathType: Prefix
  - host: test.sub.website.com
    http:
      paths:
      - backend:
          service:
            name: wordpress-service-2
            port:
              number: 80
        path: /path/wordpress2(?:/|$)(.*)
        pathType: Prefix
  tls:
  - hosts:
    - test.sub.website.com
    secretName: app-cert
status:
  loadBalancer:
    ingress:
    - hostname: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx.elb.ap-northeast-1.amazonaws.com

This is my apache file :

<Directory /var/www/html>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
    <IfModule mod_negotiation.c>
            Options -MultiViews
    </IfModule>
    Options FollowSymLinks
    AllowOverride ALL
  </Directory>

and this is how i set up wp_home and wp_siteurl on my second wordpress service wp-config.php :

define( 'WP_HOME', 'https://test.sub.website.com/path/wordpress2/' );
define( 'WP_SITEURL', 'https://test.sub.website.com/path/wordpress2/' );

I barely managed to make it work so that each path "/" or "/path/wordpress2" goes to it's respective service, the issue here is that on the second path "/path/wordpress2", when i try to access the admin page "test.sub.website.com/path/wordpress2/wp-admin, it redirects me to the "/" admin page "test.sub.website.com/wp-admin/", i tried alot of things but it didn't work, not only "wp-login" but also "wp-admin" and i believe also when logging out, is there a way to fix this from kubernetes using the server-snippet annotation ? or maybe editing wordpress config files or apache files ?

Is there a way to edit the wordpress redirection to remove this behavior ?

Edit (IMPORTANT) : updated my config Edit 2 : it looks like this the behavior of wordpress, if i access a folder it will rewrite to root path, if it's a file it will not, i tested this with multiple existing folders and new created ones, like for example i have test1 folder which does have index.html inside, "https://test.sub.website.com/wordpress2/test1" ====> https://test.sub.websie.com/test1" How am i supposed to escape this behavior ?

1 Answer 1

0

I have a similar issue, but not only with Wordpress.

I've seen that if you add a path of, say, wordpress1 to redirect to your pod, then Wordpress need to access folders inside the installation and adds, for instance, wp_admin (here is where you find the problem first when you try to setup Wordpress) the the new url does not contain your wordpress1 path and so it fails

It happens also with Nextcloud.

Now I'm unable to resolve de problem and stuck to using NodePort and opening ports on my home router.

3
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Nov 23, 2022 at 11:36
  • I have already fixed this, but ended up canceling this project for another reason. What i did was stop using regex in the paths, that's what caused me to have issues, instead i just used normal paths, like "/" for wordpress 1, and "/path/to/wordpress2/" for wordpress 2
    – logax
    Nov 23, 2022 at 13:25
  • I started by not using regex, but that does not work for me. What I see in the url is I hit the correct service, but then Wordpress from index.php redirects to wp-admin/install.php. The resulting url is my-host/wp-admin/install.php which does not contain the /wordpress route anymore and ends up pointing to my web service running under route "/" and in that web server obviously, wp-admin/install.php does not exists, thus File not found. Nov 27, 2022 at 19:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.