Sign inSign up

micrograils/wp-nginx

By micrograils

Updated 3 months ago

nginx for wordpress.

Image
Web servers
0

1.8K

micrograils/wp-nginx repository overview

Docker Image Size Docker Pulls Platforms

micrograils/wp-nginx

一个「开箱即用」的极简 Nginx 容器镜像,专为 WordPress 及静态站点优化。
基于官方 Alpine Linux,多平台构建,体积 < 5 MB,启动秒级完成。


✨ 特点

  • 超轻量:仅含官方 Nginx 二进制,无额外模块
  • 多平台:支持 linux/amd64linux/arm64 等主流架构
  • 默认暴露 80 端口,TCP 监听 0.0.0.0
  • 安全运行:默认以 nobody 用户运行,避免以 root 执行 Nginx
  • 无侵入配置:镜像内无内置站点,可自由挂载 /etc/nginx/nginx.conf/usr/share/nginx/html
  • 版本号即 Alpine 版本,与基础镜像同步,安全可追溯

🚀 快速上手

1. 启动纯静态服务
docker run -d --name web \
  -p 80:80 \
  -v $PWD/html:/usr/share/nginx/html:ro \
  micrograils/wp-nginx:latest

浏览器访问 http://localhost 即可看到挂载目录下的 index.html

2. 挂载自定义配置
docker run -d --name web \
  -p 80:80 \
  -v $PWD/nginx.conf:/etc/nginx/nginx.conf:ro \
  -v $PWD/site:/usr/share/nginx/html:ro \
  micrograils/wp-nginx:latest

🔧 进阶教程

① 与 PHP-FPM 容器组网(WordPress 典型拓扑)
services:
  nginx:
    image: micrograils/wp-nginx:latest
    container_name: wp-nginx
    ports:
      - "80:80"
    volumes:
      - ./default.conf:/etc/nginx/http.d/default.conf
      - ${LOCAL_WORDPRESS}:/var/www/html
    depends_on:
      - php
    restart: always
    networks:
      - wp-network
    healthcheck:
      test: ["CMD", "nc", "-z", "localhost", "80"]
      interval: 5s
      timeout: 3s
      retries: 5

  php:
    image: micrograils/wp-php82:latest
    container_name: wp-php
    environment:
      WORDPRESS_DB_HOST: mariadb
      WORDPRESS_DB_NAME: ${WORDPRESS_DB_NAME}
      WORDPRESS_DB_USER: ${WORDPRESS_DB_USER}
      WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
    volumes:
      - ${LOCAL_WORDPRESS}:/var/www/html
    depends_on:
      - mariadb
    restart: always
    networks:
      - wp-network
    healthcheck:
      test: ["CMD", "nc", "-z", "localhost", "9000"]
      interval: 5s
      timeout: 3s
      retries: 5

  mariadb:
    image: micrograils/wp-mariadb:latest
    container_name: wp-mariadb
    environment:
      MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD}
      MARIADB_DATABASE: ${WORDPRESS_DB_NAME}
      MARIADB_USER: ${WORDPRESS_DB_USER}
      MARIADB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
    volumes:
      - ${LOCAL_MARIADB_DATA}:/var/lib/mysql
    restart: always
    networks:
      - wp-network
    healthcheck:
      test: ["CMD", "nc", "-z", "localhost", "3306"]
      interval: 5s
      timeout: 3s
      retries: 5

  wordpress:
    image: micrograils/wp-wordpress:6.8.3
    container_name: wp-wordpress
    environment:
      WORDPRESS_DB_HOST: mariadb
    volumes:
      - ${LOCAL_WORDPRESS}:/var/www/html

networks:
  wp-network:
    driver: bridge

其中,micrograils/wp-php82 镜像基于官方 PHP 8.2 镜像,并安装了 php-fpmphp-mysql 扩展。对应的有 micrograils/wp-php83micrograils/wp-php84 等镜像供按需调整;

micrograils/wp-wordpress:6.8.3 镜像基于官方 WordPress 6.8.3 镜像,可按需更改版本号。

.env 示例:

# db info.
MARIADB_ROOT_PASSWORD=wordpress
WORDPRESS_DB_NAME=wordpress
WORDPRESS_DB_USER=wordpress
WORDPRESS_DB_PASSWORD=wordpress
# local volume.
LOCAL_WORDPRESS=./wordpress
LOCAL_MARIADB_DATA=./mariadb_data

Nginx 配置示例片段:

server {
    listen 80;
    server_name _;

    root /var/www/html;
    index index.html index.php;

    access_log /var/log/nginx/host1-access.log;
    error_log /var/log/nginx/host1-error.log;

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_pass wp-php:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        # 如果前面有 https 的反向代理
        fastcgi_param HTTPS on;
        fastcgi_param HTTP_X_FORWARDED_PROTO https;
    }

    location ~ /\.ht {
        deny all;
    }
}

启动:

docker-compose up -d

浏览器访问 http://localhost 即可看到 WordPress 安装页面。


📝 环境变量 & 端口

项目说明
暴露端口80/TCP
默认工作目录/usr/share/nginx/html
主配置文件/etc/nginx/nginx.conf
默认主机配置/etc/nginx/http.d/default.conf

🔍 常见问题

Q:容器内找不到站点?
A:请把网页文件挂载到 /usr/share/nginx/html,或替换 /etc/nginx/nginx.conf 以改变根目录。

Q:如何开启目录浏览?
A:在自定义 nginx.conf 对应 location 加 autoindex on; 即可。

Q:想使用 Alpine 其他版本?
A:构建时指定 ALPINE_VERSION 参数:

docker build --build-arg ALPINE_VERSION=3.21.0 \
  -t micrograils/wp-nginx:3.21.0 .

默认使用 Alpine 3.23。


🤝 反馈 & 贡献

GitHub 仓库
欢迎提 Issue / PR,一起让 Web 服务更轻更快!


micrograils/wp-nginx
轻到飞起,快若闪电。

Tag summary

Content type

Image

Digest

sha256:12dff969f

Size

4.5 MB

Last updated

3 months ago

docker pull micrograils/wp-nginx