Unable to access the phpfpm app

Hi @juliettet @rahul456 I have assigned a task named “Deploy Nginx and Phpfpm on Kubernetes” below are the configurations for the same.

apiVersion: v1
kind: Service
metadata:
name: app-service
spec:
type: NodePort
selector:
app: nginx
ports:
- port: 80
targetPort: 80
nodePort: 30012

apiVersion: v1
kind: ConfigMap
metadata:
name: nginx-config
data:
nginx.conf: |
events {}
http {
server {
listen 8096;
index index.html index.htm index.php;
root /var/www/html;
location ~ .php$ {
include fastcgi_params;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}
}
}

apiVersion: v1
kind: Pod
metadata:
name: nginx-phpfpm
labels:
app: nginx
spec:
volumes:
- name: shared-files
emptyDir: {}
- name: nginx-config-volume
configMap:
name: nginx-config
containers:
- name: nginx-container
image: nginx:latest
volumeMounts:
- name: shared-files
mountPath: /var/www/html
- name: nginx-config-volume
mountPath: /etc/nginx/nginx.conf
subPath: nginx.conf
- name: php-fpm-container
image: php:7.1-fpm
volumeMounts:
- name: shared-files
mountPath: /var/www/html

I have also copied the file from jump host to the respective container.

When I am trying to access the app, I am facing bad gateway error.


Any ideas?

Hi @Ashu27,

I think that it may have something to do with the config in nginx-config.
Try re-arranging/adding a couple of things in your config:

listen 8096 default_server;
listen [::]:8096 default_server;
  • set the root directory before listing the index file(s):
root /var/www/html;
index index.html index.htm index.php;

Here is my full nginx-config config map file:

kind: ConfigMap
apiVersion: v1
metadata:
  name: nginx-config
data:
  nginx.conf: |
    events {
    }
    http {
    server {
    listen 8096 default_server;
    listen [::]:8096 default_server;
        root /var/www/html;
        index index.html index.htm index.php;
        server_name _;
        location / {
            try_files $uri $uri/ =404;
        }
            location ~ \.php$ {
            include fastcgi_params;
            fastcgi_param REQUEST_METHOD $request_method;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
        }
        }
    }

I hope that this helps:-)