1.Dockerfile_wordpress
# This wordpress Dockerfile
# Version 20240222
# Base images 基础镜像
 FROM dockerstorage.xxx.com:5533/nginx/nginx-base:latest
#ENV 设置环境变量
#ENV PATH=$HOME/bin:$PATH
#ENV CLASSPATH=.:$CLASSPATH
#ADD  文件放在当前目录下,拷过去会自动解压
ADD latest-zh_CN.tar.gz /home/
ADD nginx.conf /usr/local/nginx/conf/
ADD wp-content/upgrade /home/wordpress/wp-content/upgrade
ADD wp-content/themes /home/wordpress/wp-content/themes
ADD wp-content/plugins /home/wordpress/wp-content/plugins
ADD wp-content/mu-plugins /home/wordpress/wp-content/mu-plugins
ADD wp-content/languages /home/wordpress/wp-content/languages
ADD .htaccess /home/wordpress/
ADD wp-config.php /home/wordpress/
#WORKDIR 相当于cd
WORKDIR /home
RUN chmod -R 777 /home/wordpress
#CMD 运行以下命令
CMD /home/run.sh && tail -f /dev/null
2.docker-compose.yml
# 编排服务(容器),每个服务启动一个镜像
# Time: 20240222
version: '3'
services:
   wordpress:
     restart: always
 #    env_file:
 #      - .env
     image: dockerstorage.xxx.com:5533/wordpress/dockerwordpress1:2024v1
     build:
       context: ./
       dockerfile: Dockerfile_wordpress
     ports:
       - "3301:80"
     volumes:
       - ./wp-content/uploads:/home/wordpress/wp-content/uploads
       - ./wp-content/upgrade:/home/wordpress/wp-content/upgrade
       - ./wp-content/themes:/home/wordpress/wp-content/themes
       - ./wp-content/plugins:/home/wordpress/wp-content/plugins
       - ./wp-content/mu-plugins:/home/wordpress/wp-content/mu-plugins
       - ./wp-content/languages:/home/wordpress/wp-content/languages
       - ./.htaccess:/home/wordpress/.htaccess
       - ./wp-config.php:/home/wordpress/wp-config.php
       - ./nginx.conf:/usr/local/nginx/conf/nginx.conf
     environment:
       - utf8
       - TZ=Asia/Shanghai
     extra_hosts:
       - "dockermysql.xxx.com:host-gateway"
     dns:
       - 114.114.114.114
       - 223.5.5.5
       - 8.8.8.8
     networks:
       - basic
     ulimits:
       nproc:
         soft: 65535
         hard: 65535
       nofile:
         soft: 65535
         hard: 65535
networks:
  basic:
    driver: bridge
3.wp-config.php
/**
 * The base configuration for WordPress
 *
 * The wp-config.php creation script uses this file during the installation.
 * You don't have to use the web site, you can copy this file to "wp-config.php"
 * and fill in the values.
 *
 * This file contains the following configurations:
 *
 * * Database settings
 * * Secret keys
 * * Database table prefix
 * * ABSPATH
 *
 * @link https://wordpress.org/documentation/article/editing-wp-config-php/
 *
 * @package WordPress
 */
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
if (strstr($_SERVER['HTTP_HOST'], 'dockerwp1.xxx.com')) {
 define( 'DB_NAME', 'xxx' );
/** Database username */
 define( 'DB_USER', 'xxx' );
/** Database password */
 define( 'DB_PASSWORD', 'xxx' );
/** Database hostname */
 define( 'DB_HOST', 'dockermysql.xxx.com:3306' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
} else {
 define( 'DB_NAME', 'xxx' );
/** Database username */
 define( 'DB_USER', 'xxx' );
/** Database password */
 define( 'DB_PASSWORD', 'xxx' );
/** Database hostname */
 define( 'DB_HOST', 'dockermysql.xxx.com:3306' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );
/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );
}
/**#@+
 * Authentication unique keys and salts.
 *
 * Change these to different unique phrases! You can generate these using
 * the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.
 *
 * You can change these at any point in time to invalidate all existing cookies.
 * This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define( 'AUTH_KEY',         'put your unique phrase here' );
define( 'SECURE_AUTH_KEY',  'put your unique phrase here' );
define( 'LOGGED_IN_KEY',    'put your unique phrase here' );
define( 'NONCE_KEY',        'put your unique phrase here' );
define( 'AUTH_SALT',        'put your unique phrase here' );
define( 'SECURE_AUTH_SALT', 'put your unique phrase here' );
define( 'LOGGED_IN_SALT',   'put your unique phrase here' );
define( 'NONCE_SALT',       'put your unique phrase here' );
/**#@-*/
/**
 * WordPress database table prefix.
 *
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
 */
$table_prefix = 'wp_';
/**
 * For developers: WordPress debugging mode.
 *
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 *
 * For information on other constants that can be used for debugging,
 * visit the documentation.
 *
 * @link https://wordpress.org/documentation/article/debugging-in-wordpress/
 */
define( 'WP_DEBUG', false );
/* Add any custom values between this line and the "stop editing" line. */
/*内存配置*/
define('WP_MEMORY_LIMIT', '2048M');
/*域名配置
define( 'SUNRISE', 'on' );*/
/*多站点*/
define('WP_ALLOW_MULTISITE', true);
define('MULTISITE', true);
 /*子目录*/
 define('SUBDOMAIN_INSTALL', false);
 define('DOMAIN_CURRENT_SITE', 'dockerwp1.xxx.com');
 define('PATH_CURRENT_SITE', '/');
 define('SITE_ID_CURRENT_SITE', 1);
 define('BLOG_ID_CURRENT_SITE', 1);
 /* That's all, stop editing! Happy publishing. */
/* wordpress后台编辑网站地址http改成https后,后台进不去解决办法。
define('FORCE_SSL_ADMIN', true);
define('FORCE_SSL_LOGIN', true);
$_SERVER['HTTPS'] = 'ON';
define( 'CONCATENATE_SCRIPTS', false );*/
/** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {
	define( 'ABSPATH', dirname( __FILE__ ) . '/' );
}
define("FS_METHOD", "direct");
define("FS_CHMOD_DIR", 0777);
define("FS_CHMOD_FILE", 0777);
/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';
4.nginx.conf
user  nginx;
worker_processes  4;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid        logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
    use epoll;
    worker_connections 65535;
}
http {
    include       mime.types;
    default_type  application/octet-stream;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  logs/access.log  main;
    server_tokens off;
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 600;
    gzip on;
    gzip_min_length 4k;
    gzip_buffers 8 1024k;
    gzip_http_version 1.1;
    gzip_comp_level 6;
    gzip_types text/plain text/javascript text/css text/xml application/json application/javascript application/x-javascript application/xml;
    gzip_vary on;
    server_names_hash_bucket_size 2048;
    client_header_buffer_size 1024k;
    large_client_header_buffers 8 1024k;
    client_max_body_size 1024M;
    client_header_timeout 300;
    client_body_timeout 300;
    send_timeout 300;
	
    #用于tomcat反向代理,解决nginx 504错误
    proxy_connect_timeout 300; #单位秒
    proxy_send_timeout 300;
    proxy_read_timeout 300;
    proxy_buffer_size 1024k;
    proxy_buffers 8 1024k;
    proxy_busy_buffers_size 2048k;
    proxy_temp_file_write_size 2048k;
   fastcgi_connect_timeout 300;
   fastcgi_send_timeout 300;
   fastcgi_read_timeout 300;
   fastcgi_buffer_size 1024k;
   fastcgi_buffers 8 1024k;
   fastcgi_busy_buffers_size 2048k;
   fastcgi_temp_file_write_size 2048k;
   
#   map $http_host $blogid {
#    default 0;
#    include /home/wordpress/wp-content/uploads/nginx-helper/map.conf;
#   }
    server {
        listen       80;
        server_name  localhost;
        access_log  logs/host.access.log  main;
		
        root   /home/wordpress/;
        index index.php index.html index.htm;
        location / {
            try_files $uri $uri/ /index.php?$args;
        }
		
#		location ~ ^/[_0-9a-zA-Z-]+/files/(.*)$ {
#            try_files /wp-content/blogs.dir/$blogid/files/$2 /wp-includes/ms-files.php?file=$2 ;
#            access_log off; log_not_found off; expires max;
#        }
        #avoid php readfile()
        location ^~ /blogs.dir {
            internal;
            alias /home/wordpress/wp-content/blogs.dir ;
            access_log off; log_not_found off;      expires max;
        }
        if (!-e $request_filename) {
            rewrite /wp-admin$ $scheme://$host$uri/ permanent;
            rewrite ^/[_0-9a-zA-Z-]+(/wp-.*) $1 last;
            rewrite ^/[_0-9a-zA-Z-]+(/.*\.php)$ $1 last;
        }
		
        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
        }
        #error_page  404              /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~.*\.php$ {
            root           /home/wordpress/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
			
            proxy_redirect off;
            #获取到的 Host 包含浏览器请求的 IP
            proxy_set_header Host $host;
            #获取到的 Host 包含浏览器请求的 IP 和端口
            #proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
            ###允许跨域
            add_header Access-Control-Allow-Origin $http_origin;
            add_header Access-Control-Allow-Credentials true;
            ##禁用缓存
            proxy_buffering off;
        }
        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }
    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;
    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;
    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;
    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;
    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}
}
