How to setup WordPress based on Nginx/Nginx Unit/docker-compose?

blog
Reading Time: 2 minutes



This article interested me.
– Sorry this is Japanese article.

PHP標準のアプリケーションサーバー「PHP-FPM」から「NGINX Unit」に乗り換えるだけで約8倍も応答速度が改善したというテスト結果
NGINX Unitはさまざまな言語で動作可能なオープンソースの動的アプリケーションサーバーです。PHPのアプリケーションを動作させる際にNGINX Unitを使うと、PHP-FPMを使う場合に比べて約8倍も応答速度が改善するというテスト結...



Currently my WordPress is on Raspberry Pi so I am curious performance.
I tried to setup WordPress by Nginx Unit.

TL;DR

This is directory/file structure.

$ tree
.
├── docker-compose.yml
├── myapp
│   └── config.json
└── wordpress
    └── Dockerfile

3 directories, 3 files



docker-compose.yml

version: '3.1'

services:
  wordpress:
   build:
    context: wordpress
   restart: always
   ports:
    - 8080:8080
   links:
    - db
   volumes:
    - ./myapp/config.json:/docker-entrypoint.d/config.json
    - wordpress_var_run:/var/run

  db:
   image: mariadb:latest
   restart: always
   ports:
    - 3306:3306
   environment:
    MYSQL_ROOT_PASSWORD: root
    MYSQL_USER: wordpress
    MYSQL_PASSWORD: wordpress
    MYSQL_DATABASE: wordpress
   volumes:
    - wordpress_var_run:/var/run

volumes:
  wordpress_var_run:



Dockerfile

FROM unit:php

RUN mkdir /www/ && \
	cd /www/ && \
	curl -L https://ja.wordpress.org/latest-ja.tar.gz -o wordpress.tar.gz && \
	tar zxvf wordpress.tar.gz && \
	mv wordpress/* . && \
	rm -f /www/wordpress.tar.gz && \
	chown -R www-data:www-data /www/ && \
	docker-php-ext-install mysqli && \
	docker-php-ext-enable mysqli



config.json
– You can configure applications/wordpress/processes based on your CPU cores.

{
	"listeners": {
		"*:8080": {
			"pass": "routes"
		}
	},

	"routes": [
		{
			"match": {
				"uri": [
					"*.php",
					"*.php/*",
					"/wp-admin/"
				]
			},
			"action": {
				"pass": "applications/wordpress/direct"
			}
		},
		{
			"action": {
				"share": "/www$uri",
				"fallback": {
					"pass": "applications/wordpress/index"
				}
			}
		}
	],

	"applications": {
		"wordpress": {
			"type": "php",
			"user": "www-data",
			"processes": 12,
			"targets": {
				"direct": {
					"root": "/www/"
				},

				"index": {
					"root": "/www/",
					"script": "index.php"
				}
			}
		}
	}
}



You can see initial setup page when you access http://localhost:8080.

$ sudo apt install -y docker docker-compose

$ sudo docker-compose up -d

Reference

NGINX Unit: Unit in Docker
NGINX Unit: WordPress

Conclusion

How was it?

I would like to improve below points to be able to use for me!

  • WAF(ModSecurity) activation
  • Cache enabling
  • Others

Comments

Copied title and URL