> ## Content Index
> Fetch the complete content index at: https://isoziyuan.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# docker-compose搭建的wordpress修改nginx配置文件
- URL: https://isoziyuan.com/p/100061/
- Published: 2023-03-16T04:08:43.000Z
- Updated: 2023-03-16T04:08:43.000Z
- Author: 9253462
- Tags: Docker, old-wordpress-import, #wp, #wp-post, #Import 2026-09-04 23:28

wordpress的yml文件修改如下

```
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: example_root_password
MYSQL_DATABASE: example_database
MYSQL_USER: example_user
MYSQL_PASSWORD: example_password
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
volumes:
- ./nginx.conf:/etc/nginx/conf.d/default.conf
- wp_data:/var/www/html
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_NAME: example_database
WORDPRESS_DB_USER: example_user
WORDPRESS_DB_PASSWORD: example_password
volumes:
db_data:
wp_data:
```

这个配置文件中，我们新增了一个 volume 映射，将本地的 nginx.conf 文件映射到容器内的 /etc/nginx/conf.d/default.conf 文件，从而实现自定义 Nginx 配置文件。

在该目录下创建 nginx.conf 文件，并修改需要修改的配置项。例如，您可以将以下配置项的值修改为：

```
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.php index.html index.htm;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ .php$ {
include fastcgi_params;
fastcgi_pass wordpress:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
```

这个命令将会创建并启动两个服务：MySQL 和 WordPress。WordPress 服务将会在本地的 8000 端口监听连接请求。如果您希望使用其他端口号，请修改 docker-compose.yml 文件中的对应端口号即可。

至此，您已经成功使用 Docker Compose 实现了自定义 Nginx 配置文件。