I created a docker image to server PHP code based on nginx. Everything seems to work quite well except that my request URL always needs to contain index.php (like: http://myserver.com/inde.php). If I skip “index.php” nginx will deliver just the welcome page and not automatically use index.php.
My Dockerfile
FROM alpine:3.16.2
RUN apk update && apk upgrade
RUN apk add --no-cache
bash
php8
php8-fpm
php8-json
php8-mbstring
php8-mysqlnd
php8-pdo
php8-pdo_mysql
php8-pdo_pgsql
php8-pdo_sqlite
libmcrypt-dev
libltdl
RUN apk add openssl curl ca-certificates
RUN printf "%s%s%sn"
"http://nginx.org/packages/alpine/v"
`egrep -o '^[0-9]+.[0-9]+' /etc/alpine-release`
"/main"
| tee -a /etc/apk/repositories
RUN curl -o /tmp/nginx_signing.rsa.pub https://nginx.org/keys/nginx_signing.rsa.pub
RUN openssl rsa -pubin -in /tmp/nginx_signing.rsa.pub -text -noout
RUN mv /tmp/nginx_signing.rsa.pub /etc/apk/keys/
RUN apk add nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
COPY ./index.php /usr/share/nginx/html/
EXPOSE 80
EXPOSE 443
STOPSIGNAL SIGTERM
CMD ["/bin/bash", "-c", "php-fpm8 && chmod 755 /usr/share/nginx/html/* && nginx -g 'daemon off;'"]
My default.conf
:
server {
listen *:80;
index index.php index.html;
server_name myserver;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;
location / {
try_files $uri $uri/ /index.php?$query_string;
# gzip_static on;
}
location ~ .php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Any idea what I need to fix in my setup to directly get the index.php delivered when requesting http://myserver.com?
1