Docker安装Wordpress + mysql (获得访客真实IP的传入 - 即使CloudFlare之后)

date
May 13, 2022
slug
newservice-wordpress-mysql
status
Published
summary
新服务 不包括nginx
tags
service
type
Post
URL

Summary

    步骤

    wordpress 是 在cloudflare cdn 之后,那么必须修改下nginx proxy manager获得正式访客ip

    # 如果wordpress 是 在cloudflare cdn 之后,那么必须修改下nginx proxy manager
    mkdir /data/npm_nginx_proxy_manager/data/nginx/custom
    touch /data/npm_nginx_proxy_manager/data/nginx/custom/server_proxy.conf
    echo "real_ip_header CF-Connecting-IP;" >> /data/npm_nginx_proxy_manager/data/nginx/custom/server_proxy.conf
    # 重启nginx proxy manager
    cd /data/npm_nginx_proxy_manager/ && docker compose restart
    DOCKER_MYSQL_ROOT_PASS=a8D72yp
    DOCKER_MYSQL_USER_PASS=St4Ha9U
    
    mkdir /data/wordpress; cd /data/wordpress
    cat > uploads.ini <<EOF
    file_uploads = On
    upload_max_filesize = 1000M
    post_max_size = 1000M
    memory_limit = 8192M
    max_execution_time = 600
    EOF
    
    # 这两个文件是帮助wordpress docker里面的apache拿到真实ip
    cat > remoteip.load <<EOF
    # 填写以下内容
    LoadModule remoteip_module /usr/lib/apache2/modules/mod_remoteip.so
    EOF
    cat > remoteip.conf <<EOF
    # 填写以下内容
    RemoteIPHeader X-Forwarded-For
    RemoteIPProxiesHeader X-Forwarded-By
    EOF
    
    cat > docker-compose.yml <<EOF
    version: '3.3'
    services:
    
       wordpress_db:
         image: mysql:5.7
         container_name: wordpress_mysql57
         volumes:
           - ./mysql:/var/lib/mysql
         restart: always
         environment:
           MYSQL_ROOT_PASSWORD: $DOCKER_MYSQL_ROOT_PASS
           MYSQL_DATABASE: wordpress
           MYSQL_USER: wordpress
           MYSQL_PASSWORD: $DOCKER_MYSQL_USER_PASS
       
      wordpress:
         depends_on:
           - wordpress_db
         image: wordpress:latest
         container_name: wordpress
         ports:
           - "18880:80"
         restart: always
         volumes:
           - ./var_www_html:/var/www/html
           - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
           - ./remoteip.load:/etc/apache2/mods-enabled/remoteip.load
           - ./remoteip.conf:/etc/apache2/mods-enabled/remoteip.conf
         environment:
           # 3306是默认,放不放都可以
           WORDPRESS_DB_HOST: wordpress_db:3306
           WORDPRESS_DB_NAME: wordpress
           WORDPRESS_DB_USER: wordpress
           WORDPRESS_DB_PASSWORD: $DOCKER_MYSQL_USER_PASS
           WORDPRESS_DB_CHARSET: utf8mb4
           WORDPRESS_DB_COLLATE: utf8mb4_bin
           #WORDPRESS_TABLE_PREFIX: zyx_
           #WORDPRESS_DEBUG: true
    networks:
      default:
        name: npm_nginx_proxy_manager-network
        external: true
    EOF
    
    docker-compose down; docker-compose up -d; sleep 1s; docker-compose logs -f
    
    # 基本一气呵成
    
    # 如果是mysql 8
    cat > docker-compose.yml <<EOF
    version: '3.3'
    services:
      wordpress_db:
         image: mysql:8.0
         container_name: wordpress_mysql8
         command:
          - --default_authentication_plugin=mysql_native_password
          - --character-set-server=utf8mb4
          - --collation-server=utf8mb4_unicode_ci     
         volumes:
           - ./mysql:/var/lib/mysql
         restart: always
         environment:
           MYSQL_ROOT_PASSWORD: $DOCKER_MYSQL_ROOT_PASS
           MYSQL_DATABASE: wordpress
           MYSQL_USER: wordpress
           MYSQL_PASSWORD: $DOCKER_MYSQL_USER_PASS
       wordpress:
         depends_on:
           - wordpress_db
         image: wordpress:latest
         container_name: wordpress
         ports:
           - "18880:80"
         restart: always
         volumes:
           - ./var_www_html:/var/www/html
           - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
           - ./remoteip.load:/etc/apache2/mods-enabled/remoteip.load
           - ./remoteip.conf:/etc/apache2/mods-enabled/remoteip.conf
         environment:
           WORDPRESS_DB_HOST: wordpress_db
           WORDPRESS_DB_NAME: wordpress
           WORDPRESS_DB_USER: wordpress
           WORDPRESS_DB_PASSWORD: $DOCKER_MYSQL_USER_PASS
    EOF
    
    
    
    # 如果是mariadb
    cat > docker-compose.yml <<EOF
    version: '3.3'
    services:
      wordpress_db:
            image: mariadb
            container_name: wordpress_mariadb
            volumes:
                - ./mysql:/var/lib/mysql
            restart: always
            environment:
    		       MYSQL_ROOT_PASSWORD: $DOCKER_MYSQL_ROOT_PASS
    		       MYSQL_DATABASE: wordpress
    		       MYSQL_USER: wordpress
    		       MYSQL_PASSWORD: $DOCKER_MYSQL_USER_PASS
               WORDPRESS_DB_CHARSET: utf8mb4
               WORDPRESS_DB_COLLATE: utf8mb4_bin
               #WORDPRESS_TABLE_PREFIX: zyx_
               #WORDPRESS_DEBUG: true
      wordpress:
        depends_on:
          - wordpress_db
        image: wordpress:latest
        container_name: wordpress
        ports:
          - "18880:80"
        restart: always
        volumes:
          - ./var_www_html:/var/www/html:rw
          - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
          - ./remoteip.load:/etc/apache2/mods-enabled/remoteip.load
          - ./remoteip.conf:/etc/apache2/mods-enabled/remoteip.conf
        environment:
          WORDPRESS_DB_HOST: wordpress_db
          WORDPRESS_DB_NAME: wordpress
          WORDPRESS_DB_USER: wordpress
          WORDPRESS_DB_PASSWORD: $DOCKER_MYSQL_USER_PASS
          WORDPRESS_DB_CHARSET: utf8mb4
          WORDPRESS_DB_COLLATE: utf8mb4_bin
          #WORDPRESS_TABLE_PREFIX: zyx_
          #WORDPRESS_DEBUG: true
    EOF
    
    
    
    # 看 log
    
    tail -f /data/npm_nginx_proxy_manager/data/logs/proxy-host-10_*.log
    notion image

    来个更狠的nginx+wordpress+mysql

    验证


    © Ying Bun 2021 - 2024