Sign inSign up

gleenferdinand/nginx-web

By gleenferdinand

•Updated about 2 months ago

Image
Developer tools
Web servers
Content management system
0

395

gleenferdinand/nginx-web repository overview

⁠Nginx Web Server - Docker Images

A collection of lightweight Nginx + PHP-FPM Docker images for hosting web applications and static/dynamic PHP-based files. Each directory represents a single PHP version, plus a nginxall variant that bundles most PHP versions into one image.


⁠Table of Contents


⁠Features

  • Nginx web server that is lightweight, fast, and highly concurrent.
  • PHP-FPM runs separately and is connected to Nginx through a FastCGI socket.
  • Available for PHP 5.6, 7.0, 7.2, 7.4, 8.0, 8.1, 8.2, 8.3, 8.4.
  • The nginxall variant bundles multiple PHP versions at once; the active version is selected via the PHP_VERSION environment variable.
  • Built with --platform=linux/amd64 for x86_64 machines.
  • Based on Debian bookworm; "EOL" PHP releases (5.6, 7.0, etc.) are provided through the Sury repository (packages.sury.org).
  • The web directory is mounted from the host (./www) so no rebuild is needed when content changes.
  • Access and error logs are sent to stdout / stderr to simplify docker logs.

⁠Directory Structure

webserver/nginx/
├── nginx5.6/      # PHP 5.6 image
├── nginx7.0/      # PHP 7.0 image
├── nginx7.2/      # PHP 7.2 image
├── nginx7.4/      # PHP 7.4 image
├── nginx8.0/      # PHP 8.0 image
├── nginx8.1/      # PHP 8.1 image
├── nginx8.2/      # PHP 8.2 image
├── nginx8.3/      # PHP 8.3 image
├── nginx8.4/      # PHP 8.4 image
└── nginxall/      # Multi-PHP-version image

Each version directory shares the same structure:

nginx8.3/
├── Dockerfile              # Image build definition
├── docker-compose.yml      # Run orchestration (port, volume, container name)
├── docker/
│   ├── entrypoint.sh       # Startup: start PHP-FPM + Nginx
│   └── nginx.conf          # Nginx server config (root, index, PHP via FastCGI)
└── www/
    └── index.php           # Sample page (phpinfo)

⁠Technologies Used

ComponentDescription
Web ServerNginx (high-performance web server & reverse proxy)
LanguagePHP-FPM (FastCGI Process Manager)
ProtocolFastCGI (Nginx → PHP-FPM via unix socket)
Architecturex86_64 / amd64 (--platform=linux/amd64)
Base ImageDebian bookworm
Extra PHP RepoSury (packages.sury.org) for non-distro PHP versions

⁠Image List

DirectoryPHPContainer NameHost PortBuilt Image
nginx5.65.6nginx-php569081nginx56-web
nginx7.07.0nginx-php709082nginx70-web
nginx7.27.2nginx-php729083nginx72-web
nginx7.47.4nginx-php749084nginx74-web
nginx8.08.0nginx-php809085nginx80-web
nginx8.18.1nginx-php819086nginx81-web
nginx8.28.2nginx-php829087nginx82-web
nginx8.38.3nginx-php839088nginx83-web
nginx8.48.4nginx-php849089nginx84-web
nginxall5.6–8.4nginx-all9080gleenferdinand/nginx-web:all

Note: The locally built image name follows the compose folder name (e.g. nginx83-web). The nginxall variant has an explicit image tag gleenferdinand/nginx-web:all.


⁠Usage

⁠1. Prerequisites

Make sure Docker and Docker Compose v2 are installed, and that you are on an x86_64 / amd64 machine:

docker --version
docker compose version
uname -m        # should report x86_64

Place your web files inside the www/ folder of the relevant directory, or use the bundled sample index.php.

⁠2. Running a Specific Version (e.g. PHP 8.3)
cd webserver/nginx/nginx8.3

# Build the image
docker compose build

# Start the container
docker compose up -d

# Check status
docker compose ps

Access it in your browser:

http://localhost:9088

If the bundled www/index.php (phpinfo) is still present, the PHP configuration page will be displayed.

⁠3. Running Other Versions

Repeat the same steps for the version directory you want. Adjust the port according to the table above:

cd webserver/nginx/nginx8.4
docker compose build
docker compose up -d
# Access http://localhost:9089
⁠4. Running nginxall (all PHP versions)

This image bundles several PHP-FPM versions at once. The default PHP version is determined by the PHP_VERSION environment variable (default 8.4).

cd webserver/nginx/nginxall
docker compose build
docker compose up -d

Switching the active PHP version:

# Set PHP_VERSION directly at run time
PHP_VERSION=7.4 docker compose up -d --force-recreate
# Or use .env
docker compose --env-file .env up -d
⁠5. Setting Port & PHP via .env (for nginxall)

The nginxall/.env file is already available and can be edited:

# Choose PHP version (5.6, 7.0, 7.2, 7.4, 8.0, 8.1, 8.2, 8.4)
PHP_VERSION=7.4

# Port for accessing the web (default 9080)
WORDPRESS_PORT=9080

After editing .env, rerun:

docker compose up -d --force-recreate

⁠How the Image Works

When the container starts, entrypoint.sh performs several steps:

  1. Creates the /run/php directory for PHP-FPM sockets.
  2. Starts PHP-FPM:
    • Specific version: php-fpm<v> matching the version in that directory.
    • nginxall: starts all php-fpm5.6 … php-fpm8.4, then points the .php handler to the $PHP_VERSION socket.
  3. Runs Nginx in the foreground: nginx -g 'daemon off;'.

Web request flow:

Browser ──HTTP──▶ Nginx ──FastCGI socket──▶ php-fpm<v> ──▶ /var/www/html

⁠Configuration

⁠docker/nginx.conf

A single server block that:

  • Listens on port 80 and serves the document root /var/www/html.
  • Uses index.php as the default index file.
  • Sends access/error logs to /dev/stdout and /dev/stderr.
  • Routes requests with the try_files rewriting to index.php for pretty URLs / SPA-style routing.
  • Passes .php files to PHP-FPM via fastcgi_pass unix:/run/php/php8.3-fpm.sock (version-specific in each image).
  • Denies access to .ht files for security.
⁠Volume
  • ./www:/var/www/html — your web content. Changes on the host are visible in the container immediately.

⁠Verification

Check container status & logs:

docker ps | grep nginx
docker logs <container_name>          # e.g. docker logs nginx-php83

Test the page response:

curl -i http://localhost:9088

Check the active PHP version (if www/index.php contains phpinfo()):

curl -s http://localhost:9088 | grep -i "PHP Version"

⁠Troubleshooting

SymptomSolution
Port already in useChange the port in docker-compose.yml (the ports section).
Blank page / .php extension downloadedMake sure PHP-FPM is running; check docker logs <container>.
php-fpm<v>: not foundEnsure the PHP version is actually installed in the image (or use the nginxall variant).
Old PHP version missing from Debian repoThe image uses the Sury repo; make sure the build uses docker compose build --pull.
Wrong architecture / exec format errorThese images require an x86_64 host. On ARM use the webserver/nginx_arm/ variant instead.
Want to reset / stopRun docker compose down, then docker compose up -d to start again.
Configuration changes not appliedFiles in docker/ are only read at build time; after editing them you must run docker compose build again.

Note: This directory is the x86_64 / amd64 webserver variant. For ARM devices (e.g. Raspberry Pi / Apple Silicon), use the webserver/nginx_arm/ directory in the same repository.

Tag summary

Content type

Image

Digest

sha256:84e2609fc…

Size

117.5 MB

Last updated

about 2 months ago

docker pull gleenferdinand/nginx-web