wordpress - Docker Nginx + 多个域 + 多个 wordpress 在他们自己的目录上 1 vps
问题描述
目前,我想在 1 个 vps 中运行多个具有多个域的 wordpress 站点。我希望我可以将每个 wordpress 分隔在单独的子文件夹中。
我尝试了许多不同的方法,但我第一次访问设置 wordpress 时总是遇到 404 错误。
这是我在 nginx error.log 中的错误日志
*6 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 192.168.63.1, server: site1.com, request: "GET / HTTP/1.0", upstream: "fastcgi://172.21.0.4:9000", host: "192.168.63.130"
谁能向我解释我做错了什么?谢谢!
码头工人-compose.yml
version: '3.6'
services:
nginx:
image: nginx:1.15.7-alpine
container_name: nginx
ports:
- '80:80'
- '443:443'
volumes:
- ./nginx:/etc/nginx
- ./logs/nginx:/var/log/nginx
- ./wordpress:/var/www/html
- ./certs:/etc/letsencrypt
- ./certs-data:/data/letsencrypt
links:
- site1
- site2
restart: always
mysql:
image: mariadb
container_name: mysql
volumes:
- ./mysql:/var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=password
restart: always
site1:
image: wordpress:php7.2-fpm-alpine
container_name: site1
volumes:
- ./wordpress/site1:/var/www/html/
- ./php/conf.d/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
environment:
- WORDPRESS_DB_NAME=site1
- WORDPRESS_TABLE_PREFIX=wp_
- WORDPRESS_DB_HOST=mysql
- WORDPRESS_DB_PASSWORD=password
links:
- mysql
restart: always
site2:
image: wordpress:php7.2-fpm-alpine
container_name: site2
volumes:
- ./wordpress/site2:/var/www/html/
- ./php/conf.d/uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
environment:
- WORDPRESS_DB_NAME=site2
- WORDPRESS_TABLE_PREFIX=wp_
- WORDPRESS_DB_HOST=mysql
- WORDPRESS_DB_PASSWORD=password
links:
- mysql
restart: always
site1
/nginx/sites-enabled/site1 ( site2与替换相同site2
fastcgi_cache_path /var/cache/nginx/site1 levels=1:2 keys_zone=site1:100m inactive=60m;
server {
# Ports to listen on
listen 80;
listen [::]:80;
# Server name to listen for
server_name site1.com;
# Path to document root
root /var/www/html/site1;
# File to be used as index
index index.php;
# Overrides logs defined in nginx.conf, allows per site logs.
access_log /var/log/nginx/site1.access.log;
error_log /var/log/nginx/site1.error.log crit;
# Default server block rules
include global/server/defaults.conf;
# Fastcgi cache rules
include global/server/fastcgi-cache.conf;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
include global/fastcgi-params.conf;
fastcgi_pass site1:9000;
# Skip cache based on rules in global/server/fastcgi-cache.conf.
fastcgi_cache_bypass $skip_cache;
fastcgi_no_cache $skip_cache;
# Define memory zone for caching. Should match key_zone in fastcgi_cache_path above.
fastcgi_cache site1;
# Define caching time.
fastcgi_cache_valid 60m;
}
# Rewrite robots.txt
rewrite ^/robots.txt$ /index.php last;
# Uncomment if using the fastcgi_cache_purge module and Nginx Helper plugin (https://wordpress.org/plugins/nginx-helper/)
# location ~ /purge(/.*) {
# fastcgi_cache_purge fastcgi-cache.com "$scheme$request_method$host$1";
# }
}
# Redirect www to non-www
server {
listen 80;
listen [::]:80;
server_name www.site1.com;
return 301 $scheme://site1.com$request_uri;
}
解决方案
我添加一个 Dockerfile site1_build/Dockerfile
:
FROM wordpress:php7.2-fpm
WORKDIR /var/www/html/site1
在docker-compose.yml
文件中:
site1:
build: ./site1_build
container_name: site1
volumes:
- ./wordpress/site1:/var/www/html/site1
推荐阅读
- amazon-web-services - Cognito 不会在 CustomSMSSender 中调用 Lambda 函数
- angular - dns-packet 的 NPM 审计问题
- android - Glide 没有在 Kotlin 的回收视图中显示 Firestore 图像
- wpf - 在 ComboBox 中使用 Button 不会进行选择
- python-3.x - 多个队列在dask
- css - 在 Rails 中,pagey 样式不可自定义
- node.js - Css Minimizer Plugin: postcss-svgo: Error: Plugin name should be specified [Gatsby]
- c# - Grpc.Channel 连接超时
- python - 如何使用 GUI 连接后端 Python 代码
- css - 合并媒体查询