WordPress
# 拉取镜像 docker pull mysql # 创建容器 docker run \ -p 23306:3306 \ -v /root/wordpress/mysql:/var/lib/mysql \ -e TZ=Asia/Shanghai \ -e MYSQL_DATABASE=db_wordpress \ -e MYSQL_ROOT_PASSWORD=F10378 \ --name wordpress_mysql \ --restart always \ -itd mysql:latest # 拉取镜像 docker pull wordpress # 创建容器 docker run \ -p 20321:80 \ -p 20322:443 \ -v /root/wordpress/www/html:/var/www/html \ --name wordpress \ --restart always \ -itd wordpress:latest # 复制证书 cp -r /root/cert /root/wordpress/www/html # 进入容器 docker exec -it wordpress /bin/bash # 加载ssl模块 a2enmod ssl # ----------------------------------------------------------------- # 修改 /etc/apache2/sites-available/000-default.conf <VirtualHost *:80> <Directory "/var/www/html"> RewriteEngine on RewriteBase / RewriteRule ^/?(.*) https://fslse.top:20322/$1 [R,L] </Directory> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost> # 修改 /etc/apache2/sites-available/default-ssl.conf <IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin webmaster@localhost ServerName fslse.top DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined SSLEngine on SSLCertificateFile /var/www/html/cert/fslse.top_public.crt SSLCertificateKeyFile /var/www/html/cert/fslse.top.key SSLCertificateChainFile /var/www/html/cert/fslse.top_chain.crt <FilesMatch "\.(cgi|shtml|phtml|php)$"> SSLOptions +StdEnvVars </FilesMatch> <Directory /usr/lib/cgi-bin> SSLOptions +StdEnvVars </Directory> </VirtualHost> </IfModule> # ----------------------------------------------------------------- # 设置软链接 ln -s /etc/apache2/sites-available/default-ssl.conf /etc/apache2/sites-enabled/default-ssl.conf # 启动重定向 a2enmod rewrite # 重启 service apache2 restart # 重启 docker restart wordpress # 测试 curl http://fslse.top:20321 -v curl https://fslse.top:20322 -v # -----------------------------------------------------------------
问题1:站点还是无法用https访问!!!
解决办法:
注意 curl https://fslse.top:20322 -v 这条命令的结果,当你确定没有任何问题的时候再进行下一步!!!
进入 wordpress 后台,将 “ 设置 -> 常规 ” 中的 “ WordPress 地址(URL) ” 和 “ 站点地址(URL) ” 修改为 https://fslse.top:20322 ,保存更改后就可以通过 https 进行访问了。
问题2:虽然在80端口设置了重定向,但还是无法通过 http://fslse.top:20321 来访问!!!
可能的原因:
wordpress 一开始的访问地址为 http://fslse.top:20321 ,而现在被修改成了 https://fslse.top:20322 ,这导致了通过 http://fslse.top:20321 进行访问时,
会被 wordpress 重定向到 http://fslse.top:20322 ,apache2 80端口的配置文件中的重定向压根没起作用,而20322端口又是使用了ssl的端口,无法通过http来访问。
依据:
注释掉apache2 80端口的配置文件中的重定向,然后使用浏览器的开发者工具或者在Ubuntu中使用 curl http:fslse.top:20321 -i -l 命令来观察请求的变化,结果是通过 http://fslse.top:20321 进行访问时,还是会走 http://fslse.top:20322 。
目前不知道怎么解决,但也没有解决的必要。毕竟平时使用的时候我们一般也不会通过“域名加端口”的方式来访问,而是通过三级域名进行访问。
问题3:wordpress上传主题压缩包时报错 ,“ 上传的文件大小超过 php.ini 文件中定义的 upload_max_filesize 值。 ”
解决办法:
# 进入容器 docker exec -it wordpress /bin/bash # 复制 cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini # 进入目录 cd /usr/local/etc/php # 编辑 vim php.ini # vim编辑器命令模式下使用 /upload_max_filesize # 找到 upload_max_filesize 字符串的位置 # 修改为 upload_max_filesize = 256M # /post_max_size # 修改为 post_max_size = 256M # /memory_limit # 修改为 memory_limit = 512M # 退出 exit # 重启 docker restart wordpress