wordpress - 如何使用WPML的 'different domain per language'配置dockerized wordpress nginx?

标签 wordpress docker nginx wpml

现在这是 cool.XXXXXX.com 正在使用的域。

我想显示我的日语版本,域名为 jp-cool.XXXXXX.com

我使用letcrypt设置SSL

certbot certonly --standalone -d jp-cool.XXXXXX.com --staple-ocsp -m <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="780a17170c381208551b17171456202020202020561b1715" rel="noreferrer noopener nofollow">[email protected]</a> --agree-tos

docker-compose.yml

version: "3.3"
services:
  XXXXweb-db:
    image: mysql:5.7.26
    restart: always
    container_name: XXXXweb-db
    environment:
      MYSQL_HOST: XXXXweb-db
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DB_ROOT_PASS}
    volumes:
      - ./data:/var/lib/mysql:delegated
      - ./logs/mysql:/var/log/mysql:delegated
      - ./conf/mysql.cnf:/etc/mysql/my.cnf:delegated
    ports:
        - "3306:3306"
    expose:
        - 3306
    security_opt:
      - seccomp:unconfined
  
  XXXXweb-nginx:
    image: nginx:1.17.1-alpine
    restart: always
    ports:
      - "80:80"
      - "443:443"
    expose:
      - 80
      - 443
    volumes:
      - ./logs:/var/log/nginx:delegated
      - ./conf/${NGINX_CONFIG_NAME}:/etc/nginx/nginx.conf:delegated
      - ${CERT_PATH}:/etc/letsencrypt:delegated
      - ./:/wwwroot:delegated
    depends_on:
      - XXXXweb-db
      - XXXXweb-php
    logging:
        driver: "json-file"
        options:
          max-size: "100m"

  XXXXweb-php:
    image: php-XXXX
    restart: always
    ports:
      - "9000:9000"
    expose:
      - 9000
    volumes:
      - ./logs:/var/log:delegated
      - ./:/wwwroot:delegated
    healthcheck:
      test: ["CMD-SHELL", "pidof php-fpm"]
      interval: 5s
      retries: 12
    logging:
      driver: "json-file"
      options:
        max-size: "100m"

nginx-server.conf

user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events { worker_connections 1024; }

http {
        include /etc/nginx/mime.types;
        default_type application/octet-stream;
        log_format main '$http_x_forwarded_for - $remote_user [$time_local] "$request" $status $body_bytes_sent "$http_referer" "$http_user_agent"';
        access_log on;
        sendfile on;
        keepalive_timeout 65;
        client_max_body_size 100M;

        server {
            listen 80;
            server_name cool.XXXXXX.com;
            return 301 https://cool.XXXXXX.com$request_uri;
        }

        server {
                listen [::]:443 ssl ipv6only=on; # managed by Certbot
                listen 443 ssl; # managed by Certbot
                ssl_certificate /etc/letsencrypt/live/cool.XXXXXX.com/fullchain.pem; # managed by Certbot
                ssl_certificate_key /etc/letsencrypt/live/cool.XXXXXX.com/privkey.pem; # managed by Certbot
                
                ## Your website name goes here.
                server_name cool.XXXXXX.com;
                ## Your only path reference.
                root /wwwroot;
                ## This should be in your http block and if it is, it's not needed here.
                index index.php;

                location = /favicon.ico {
                        log_not_found off;
                        access_log off;
                }

                location = /robots.txt {
                        allow all;
                        log_not_found off;
                        access_log off;
                }

                location / {
                        # This is cool because no php is touched for static content.
                        # include the "?$args" part so non-default permalinks doesn't break when using query string
                        try_files $uri $uri/ /index.php?$args;
                }

                location ~ \.php$ {
                        try_files $uri =404;
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        fastcgi_pass XXXXweb-php:9000;
                        fastcgi_index index.php;
                        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_param PATH_INFO $fastcgi_path_info;
                }

                location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                        expires max;
                        log_not_found off;
                }
        }
}

添加后

        server {
            listen 80;
            server_name jp-cool.XXXXXX.com;
            return 301 https://jp-cool.XXXXXX.com$request_uri;
        }

它适用于 http 不安全连接。

但是,在我添加 jp-cool.XXXXXX.comcool.XXXXXX.com 重复部分后,只有其中一个可以工作。

当我设置“每种语言不同的域”时,我在 WPML 面板上得到了 invalid

没有docker,我可以在本地nginx /etc/nginx/site-available中设置不同的域

但我无法使用 dockerized nginx 进行设置。

最佳答案

如果您没有通配符证书,您唯一的选择是为每个证书复制服务器 block 。具体方法如下:

        server {
                # this part changes per certificate
                ssl_certificate /etc/letsencrypt/live/cool.XXXXXX.com/fullchain.pem; # managed by Certbot
                ssl_certificate_key /etc/letsencrypt/live/cool.XXXXXX.com/privkey.pem; # managed by Certbot                
                server_name cool.XXXXXX.com;
                include common;
        }
        server {
                # this part changes per certificate
                ssl_certificate /etc/letsencrypt/live/jp-cool.XXXXXX.com/fullchain.pem; # managed by Certbot
                ssl_certificate_key /etc/letsencrypt/live/jp-cool.XXXXXX.com/privkey.pem;
                server_name jp-cool.XXXXXX.com;
                include common;
         }

为了遵循 DRY 原则,请将服务器 block 的其余部分放入单独的文件中。我使用“common”作为该文件的名称,您需要将其放置在 /etc/nginx/ 中,否则您必须更改上面 block 中的路径。 /etc/nginx/common:

                listen [::]:443 ssl ipv6only=on; # managed by Certbot
                listen 443 ssl; # managed by Certbot
                root /wwwroot;
                ## This should be in your http block and if it is, it's not needed here.
                index index.php;

                location = /favicon.ico {
                        log_not_found off;
                        access_log off;
                }

                location = /robots.txt {
                        allow all;
                        log_not_found off;
                        access_log off;
                }

                location / {
                        # This is cool because no php is touched for static content.
                        # include the "?$args" part so non-default permalinks doesn't break when using query string
                        try_files $uri $uri/ /index.php?$args;
                }

                location ~ \.php$ {
                        try_files $uri =404;
                        fastcgi_split_path_info ^(.+\.php)(/.+)$;
                        fastcgi_pass XXXXweb-php:9000;
                        fastcgi_index index.php;
                        include fastcgi_params;
                        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                        fastcgi_param PATH_INFO $fastcgi_path_info;
                }

                location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                        expires max;
                        log_not_found off;
                }

您还可以使用一台服务器进行 HTTPS 重定向:

        server {
            listen 80;
            server_name cool.XXXXXX.com;
            server_name jp-cool.XXXXXX.com;
            return 301 https://$host$request_uri;
        }

关于wordpress - 如何使用WPML的 'different domain per language'配置dockerized wordpress nginx?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65445111/

相关文章:

ruby-on-rails - 在入口脚本中进行捆绑安装和 yarn 安装-Docker

mysql - 是否可以将 Wordpress 博客数据库移动到 Rails 数据库?

javascript - jQuery Ready 的两个定义

php - 主页的不同 CSS

wordpress - 这个 vcl_hash 函数有什么作用?

docker - 如何在if语句中更改docker ARG值?

docker - Azure DevOps在同一代理(VM)上的多个Docker容器

mysql - 运行 nginx 入口 Controller kubernetes 时需要服务的(内部)名称

Nginx子域配置

nginx - Nginx中的worker_processes和worker_connections是什么?