简体   繁体   中英

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

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.

所以解决方案:efs 需要挂载到同一路径的两个容器上,这样两个容器都可以访问它。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM