TrafeX / docker-php-nginx

Docker image with PHP-FPM 8.3 & Nginx 1.26 on Alpine Linux
https://hub.docker.com/r/trafex/php-nginx
MIT License
1.37k stars 736 forks source link

Chopped up nginx.conf, extracted the server block to /conf.d/default.conf #109

Closed doedje closed 1 year ago

doedje commented 1 year ago

As requested in #98

If you just want to redefine a different server-block you can put .conf files in your conf.d directory like:

# conf.d/redirect.conf
server {
    listen 80 default_server;
    listen [::]:80 default_server;
    return 301 https://$host$request_uri;
}

and

# conf.d/my-https-site.conf
server {
    listen 443 default_server ssl;
    listen [::]:443 default_server ssl;
    ...
}

You can now run the image as a new container with:

docker run -v "`pwd`/conf.d:/etc/nginx/conf.d" -p 80:80  -p 443:443 trafex/php-nginx

NOTE: don't forget to add a server-block for the healthcheck:

# conf.d/healthcheck.conf
server {
    listen 8080;
    listen [::]:8080;
    # Allow fpm ping and status from localhost
    location ~ ^/(fpm-status|fpm-ping)$ {
        access_log off;
        allow 127.0.0.1;
        deny all;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_pass unix:/run/php-fpm.sock;
    }
}

_EDIT: removed 'defaultserver' from the healthcheck server-block and fixed a typo

TrafeX commented 1 year ago

Hi @doedje,

Thank you for your contribution! That's indeed exactly what's needed to split the http and server config. I'll merge this in. Nice work!