Home > database >  Nginx - wordpress fpm - getting 404 on images stored in wp-content/uploads (symbolic link to EFS)
Nginx - wordpress fpm - getting 404 on images stored in wp-content/uploads (symbolic link to EFS)

Time:11-03

I am running Nginx and wordpress-fpm in Kubernetes within one pod. Images are stored in EFS and EFS folder linked to wp-content/uploads folder as a symbolic link. EFS folder is available and I can access it from the container.

This is my deployment file:

    apiVersion: apps/v1
kind: Deployment
metadata:
  name: -deployment
  labels:
    app: MASSEDIT
spec:
  replicas: 1
  selector:
    matchLabels:
      app: MASSEDIT
  template:
    metadata:
      labels:
        app: MASSEDIT
    spec:
      volumes:
        - name: efs-pvc
          persistentVolumeClaim:
            claimName: -efs-storage-claim
        - name: shared-files
          emptyDir: {}
        - name: nginx-config
          configMap:
            name: -nginx-configmap
      containers:
        - image: DONTTOUCH-replace-me-kustomization
          name: app
          ports:
          - containerPort: 9000
            protocol: TCP
          volumeMounts:
          - mountPath: /var/www/html
            name: shared-files
          - mountPath: /shared
            name: efs-pvc
        - image: nginx
          name: nginx
          ports:
          - containerPort: 80
            protocol: TCP
          volumeMounts:
          - mountPath: /var/www/html
            name: shared-files
          - mountPath: /etc/nginx/conf.d/default.conf
            name: nginx-config
            subPath: nginx.conf
        

This is my Nginx config map:

kind: ConfigMap
apiVersion: v1
metadata:
  name: -nginx-configmap
data:
  nginx.conf: |
        server {
                listen       80;
                server_name some server;
                root   /var/www/html/;
                index index.php index.html index.htm;


                # Logs
                access_log /var/log/nginx/webapp-access.log;
                error_log /var/log/nginx/webapp-error.log;

                location / {
                # try_files $uri $uri/ =404;
                # try_files $uri $uri/ /index.php?q=$uri&$args;
                        try_files $uri $uri/ /index.php?$query_string;
                }


                location ~ \.php$ {
                        fastcgi_param HTTPS 1;
                        fastcgi_split_path_info ^(. \.php)(/. )$;
                        fastcgi_pass 127.0.0.1:9000;
                        fastcgi_index index.php;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        include fastcgi_params;
                        fastcgi_buffers 8 16k;
                        fastcgi_buffer_size 32k;
                        fastcgi_connect_timeout 300s;
                        fastcgi_send_timeout 60;
                        fastcgi_read_timeout 60;
                }
      
        }

I am able to load all pages and everything works fine except media (images) that are stored in wp-content/uploads. I am getting 404 on loading this images.

My nginx by default running as root. wp-content folder owner is www-data:www-data There is nothing in the fpm log or nginx error log.

Cant understand and debug the root cause. Is it possible that Nginx is not folowing symbolic links?

UPD1.

I was checking nginx and nginx container and I am not able to access the symbolic link from it. So my symbolic link is created in app container and nginx is not able to see it.

CodePudding user response:

So the solution: efs need to be mounted to both containers at the same path, so both containers are able to access it.

  • Related