Wordpress: [Kubernetes] Wordpress (PHP-FPM) + Nginx not serving content

Created on 25 May 2018  路  6Comments  路  Source: docker-library/wordpress

got a problem with a wordpress + nginx deployment not serving php content
It can server html documents

nginx log:

[23/May/2018:04:33:56 +0000] "GET / HTTP/1.1" 200 5 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"

wordpress (phpfpm) log:

127.0.0.1 -  23/May/2018:04:33:56 +0000 "- " 200

So wordpress fpm is getting the request but nothing is returned/computed?

nginx.conf:

user  www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    index         index.php;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    client_body_buffer_size 32k;
    client_header_buffer_size 1k;
    large_client_header_buffers 4 8k;
    # php max upload limit cannot be larger than this
    client_max_body_size 33m;

    proxy_buffers 16 32k;
    proxy_buffer_size 64k;

    fastcgi_buffers 16 128k;
    fastcgi_buffer_size 256k;

    upstream php {
        #server unix:/tmp/php-cgi.socket;
        server localhost:9000;
    }

    fastcgi_cache_path /var/run/nginx-cache levels=1:2 keys_zone=WORDPRESS:100m inactive=60m;
    fastcgi_cache_key "$scheme$request_method$host$request_uri";
    fastcgi_cache_use_stale error timeout invalid_header http_500;
    fastcgi_ignore_headers Cache-Control Expires Set-Cookie;

    real_ip_header X-Forwarded-For;
    set_real_ip_from 0.0.0.0/0;

    limit_req_zone $binary_remote_addr zone=one:10m rate=16r/s;
    limit_req_zone $binary_remote_addr zone=two:10m rate=30r/m;
    limit_conn_zone $binary_remote_addr zone=addr:10m;
    limit_conn addr 10;
    limit_conn_status 444;

    include /etc/nginx-conf/conf.d/*.conf;
}

Wordpress.conf (/etc/nginx-conf/conf.d):

server {
      ## Your website name goes here.
      server_name _;
      ## Your only path reference.
      ## This should be in your http block and if it is, it's not needed here.
      # index index.php;

      root /var/www/html;
      include /etc/nginx-conf/global/*.conf;

      location / {
              # This is cool because no php is touched for static content.
              # include the "?$args" part so non-default permalinks doesn't break when using query string
              try_files $uri /index.php?$args;
      }

      location ~ \.php$ {
              #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini
              limit_req zone=one burst=12 nodelay;
              include fastcgi_params;
              fastcgi_pass php;
      }
}

Deployment:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: wordpress
  labels:
    app: wordpress
  namespace: default
spec:
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app: wordpress
  template:
    metadata:
      labels:
        app: wordpress
    spec:   
      containers:
      - name: wordpress
        image: wordpress:4.9-php7.2-fpm
        env:
        - name: WORDPRESS_DB_HOST
          value: mysql-service
        - name: WORDPRESS_DB_NAME
          value: wordpress
        - name: WORDPRESS_DB_USER
          value: wordpress
        - name: WORDPRESS_DB_PASSWORD
          valueFrom:
            secretKeyRef:
              name: mysql-wordpress-pass
              key: password
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
        - name: php
          mountPath: /usr/local/etc/php/conf.d
        - name: cache
          mountPath: /var/run/nginx-cache

      - name: nginx
        image: nginx:1.14
        ports:
        - containerPort: 80
        env:
        volumeMounts:
        - name: wordpress-persistent-storage
          mountPath: /var/www/html
        - name: nginx
          mountPath: /etc/nginx/
        - name: nginx-conf-d
          mountPath: /etc/nginx-conf/conf.d
        - name: nginx-global
          mountPath: /etc/nginx-conf/global
        - name: nginx-html
          mountPath: /etc/nginx-conf/html
        - name: cache
          mountPath: /var/run/nginx-cache
      volumes:
      - name: wordpress-persistent-storage
        persistentVolumeClaim:
          claimName: wordpress-pvc
      - name: php
        configMap:
          name: php
      - name: cache
        emptyDir:
          medium: Memory
      - name: nginx
        configMap:
          name: nginx
      - name: nginx-conf-d
        configMap:
          name: nginx-conf-d
      - name: nginx-global
        configMap:
          name: nginx-global
      - name: nginx-html
        configMap:
          name: nginx-html

let me know if you need additional configuration documents

question

Most helpful comment

Within the same kubernetes pod, containers interact via localhost

Source:
https://kubernetes.io/docs/concepts/workloads/pods/pod/

All 6 comments

Regular Wordpress-php7.2 works, fpm doesn't seem to be working

    upstream php {
        #server unix:/tmp/php-cgi.socket;
        server localhost:9000;
    }

localhost looks wrong. this should point to the wordpress container.

Within the same kubernetes pod, containers interact via localhost

Source:
https://kubernetes.io/docs/concepts/workloads/pods/pod/

Can you create a smaller reproducer that doesn't require/use Kubernetes? I think that'll be helpful for folks to be able to help you more easily.

In the end, I think this is very, very likely to be an issue with your NGINX configuration (which in my experience is tricky to get right for FPM), not really something we can fix in the image (so you might even have more luck getting experienced folks who can help by posting to the Docker Community Forums, the Docker Community Slack, or Stack Overflow).

Since this issue doesn't seem to denote any errors with the image I'm going to close, if there is something reproducible to show an issue with the image then I'll re-open.

@Coolfeather2 Yes, but since the wordpress is exposed as a service (it should be if not); its best to use {WORDPRESS_SERVICE_NAME} instead of localhost.

Was this page helpful?
0 / 5 - 0 ratings