Docker Nginx +多个域+多个wordpress在自己的目录中以1 vps的速度运行

时间:2019-01-01 02:52:11

标签: wordpress docker nginx

当前,我想以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"

有人可以向我解释我在做什么错吗?谢谢!

docker-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

/ nginx / sites-enabled / site1(site2相同,将site1替换为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;
}

1 个答案:

答案 0 :(得分:0)

我添加了一个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