I am struggling to get nginx
processing *.php
files in a container app. I have read all over the places, even here in SO, but everything I have tried still not working for me meaning I am able to access the web server through http://localhost:8080
but if I do http://localhost:8080/index.php
I get a 404. I have check the path /app/src
on both containers: php-fpm
and nginx
and it has a index.php
file which contains just: <?php phpinfo(); ?>
.
I am building the nginx
container using the following Dockerfile
:
#syntax=docker/dockerfile:1.4
FROM nginx:alpine-slim
COPY --link ../nginx/conf.d/nginx-dev.conf /etc/nginx/conf.d/
COPY --link ../nginx/conf.d/php-upstream.conf /etc/nginx/conf.d/
and the content of each of those files is as follow:
# nginx-dev.conf
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name app.localhost localhost;
root /srv/app;
location / {
# try to serve file directly, fallback to index.php
try_files $uri @rewriteapp;
}
location @rewriteapp {
rewrite ^(.*)$ /index.php/\ last;
}
location ~* .php(/|$) {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
fastcgi_pass php-upstream;
fastcgi_split_path_info ^(.+.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
# Serve PHP-FPM status page, note that we should not activate this in production
location ~ ^/status$ {
access_log off;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass php-upstream;
}
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_min_length 1024;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript application/vnd.ms-fontobject application/x-font-ttf font/opentype image/svg+xml image/x-icon;
gzip_static on;
server_tokens off;
disable_symlinks off;
fastcgi_buffer_size 256k;
fastcgi_buffers 4 512k;
fastcgi_busy_buffers_size 512k;
error_log /var/log/nginx/app_error.log;
access_log /var/log/nginx/app_access.log combined buffer=64k flush=5m;
}
# php-upstream.conf
upstream php-upstream {
server php-fpm:9000;
}
last but not least, this is the PHP-FPM configuration that goes inside the php-fpm container:
[global]
daemonize = no
process_control_timeout = 20
[www]
listen = /var/run/php/php-fpm.sock
clear_env = no
listen.mode = 0666
Can any see something that I am not? Where is the problem here?