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

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, it redirects me to the "/" admin page, i tried alot of things but they 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 ?

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 service wp-config.php :

define( 'WP_HOME', 'https://test.sub.website.com/path/wordpress2/' );
define( 'WP_SITEURL', 'https://test.sub.website.com/path/wordpress2/' );
define('WP_CONTENT_URL', 'https://test.sub.website.com/path/wordpress2/wp-content');
define('WP_ADMIN_URL', 'https://test.sub.website.com/path/wordpress2/wp-admin');

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 ?

logax
  • 33
  • 6
  • 1. Delete second section `- host` from your code because you have the same host for both path so they should be under one `- hosts` section. It seems that you have too many spaces in second `- host` and it is on the same hierarchy as `http` and that is why it doesn't work for second path. 2. Did you try change `/path/wordpress2(?:/|$)(.*)` to `/path/wordpress2/?(.*)` or `/path/wordpress2/`? [Here](https://stackoverflow.com/questions/66299680/kubernetes-ingress-path) and [here](https://stackoverflow.com/questions/64946195/invalid-value-for-nginx-path/64970491#64970491) were a similar problem. – RadekW Feb 07 '22 at 13:33
  • Thank you for the comment, actually the k8s code is correct, i just pasted it here wrongly, i'll change it, i also tried the suggestions with no luck :/, the only best solution that almost works perfectly is the current one i'm using, the only issue is with the wp-admin, and i think it's a wordpress issue redirection :/. – logax Feb 07 '22 at 13:59

0 Answers0