Back  
 

Docker nginx / php notes

I had some trouble getting nginx with php-fpm to operate. So I tried to get working a simple setup to nut-out the nuances. I got it working using php-fpm socket with Apline Linux on 2 Docker instances, one running Nginx and the other php-fpm. Next try would be a second Nginx in separate Docker and then trying IP TCP connectivity instead of socket file.

To run and control nginx.

  • nginx to run.
  • nginx -h to get all help / options
  • nginx -s signal, where signal maybe:
    • stop for fast shutdown
    • quit for graceful shutdown
    • reload to reload the configuration files
    • reopen to reopen the log files
  • nginx -t to test configuration
  • nginx -c config_file to start nginx with a non default config file. Default config file is /etc/nginx/nginx.conf.

/etc/nginx/fastcgi.conf

/etc/nginx/fastcgi_params

/etc/nginx/mime.types

/etc/nginx/nginx.conf

/etc/nginx/scgi_params

/etc/nginx/uwsgi_params

/etc/nginx/http.d/

/etc/nginx/http.d/default.conf

/etc/nginx/modules/

This directory is empty.

/etc/nginx/conf.d/

This directory does not exist. This is a concern as the default nginx configuration nginx.conf references this directory. Of course the /etc/nginx/conf.d is a default override directory, so it can be created on use.

/usr/share/nginx/http-default_server.conf

/var/lib/nginx/html/index.html

There is following empty subdirectory structure: /var/www/localhost/htdocs

Unless otherwise configured nginx reads the default configuration file at /etc/nginx/nginx.conf. I replaced the default nginx.conf user directive to match that in the /etc/php/php-fpm.d/www.conf for the socket listen.owner and listen.group directives. I do not change the www.conf user and group directives, which are default nobody This file has dynamic module overrides and root code snippet updates. The main virtual host configuration files are located in sub-directory /etc/nginx/http.d

Place this at following location; /var/www/test/index.html

basic static html test page

The directory /etc/nginx/http.d/ should already exit. Create test.conf.

/etc/nginx/http.d/test.conf

The existing default.conf return 404 error and will conflict with the new simple configuration and need to be removed.

nginx seems to have the following log levels # [ debug | info | notice | warn | error | crit ]. Hence when developing and creating a html server use of info or notice is probably used whereas warn or error level logging would probably be used for a normal running html server.

In order to run nginx in the foreground us echo “daemon off;” » /etc/nginx/nginx.conf. I tried nginx -g 'daemon off;', but that did not work.

There are 2 php executables, php a cli version (/usr/bin/php82) and php-fpm for fpm-fcgi (/usr/sbin/php-fpm82). We are interested in the fpm type and it can be run in foreground using flag -F or --nodaemonize. The php-fpm modules are stored here /usr/lib/php82/modules. There is /etc/php82 that has the configuration files.

/etc/php82/php-fpm.conf

/etc/php82/php.ini

/etc/php82/php-fpm.d/www.conf

/etc/nginx/http.d/fastcgi_test.conf

/var/www/test/test.php

/var/www/test/phpinfo.php

  • /app/www/public/data/pages/docker_notes/nginx-php-notes.txt
  • Last modified: 2024-02-24 Sat wk08 14:19
  • by baumkp