ubuntu服务器安装wordpress
ubuntu 系统没有docker直接
snap install docker
拉取wordpress镜像
docker pull wordpress:php7.3
创建mysql数据文件夹
mkdir -p /data/wordpress/
运行mysql5.7镜像,没有会直接拉取
docker run -d –name my_mysql –restart always -e MYSQL_ROOT_PASSWORD=redhat -e MYSQL_DATABASE=db_web -p 3710:3306 mysql:5.7
运行wordpress容器
docker run -d –name my_wordpress –restart always –link my_mysql -e WORDPRESS_DB_HOST=ip:3710 -e WORDPRESS_DB_USER=root -e WORDPRESS_DB_PASSWORD=redhat -e WORDPRESS_DB_NAME=db_web -p 8167:80 wordpress:php7.3
访问wordpress后台
http://localhost:8167/wp-admin/install.php
nginx代理并添加https服务
安装nginx,apt install nginx
编辑 /etc/nginx/site-enable/default
配置文件
server {
listen 80;
server_name www.xxx.com;
rewrite ^(.*) https://$host$1 permanent;
}
server {
listen 443 ssl http2 default_server;
server_name www.xxx.com;
ssl_certificate "/opt/cer/aispider.cc.pem";
ssl_certificate_key "/opt/cer/aispider.cc.key";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
location / {
if ($host !~* ^www) {
set $name_www www.$host;
rewrite ^(.*) https://$name_www$1 permanent;
}
proxy_pass http://www.xxx.com:8167;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_read_timeout 86400;
}
}
进入docker 容器编写wordpress配置文件
docker ps -a #查询到wordpress容器ID
docker exec -it ID /bin/bash #一般会直接进入到php文件目录
apt-get update && apt-get install -y vim #安装vim
vim wp-cofing.php #编辑php配置文件
添加如下内容
define('FORCE_SSL_ADMIN', true);
if (strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false){
$_SERVER['HTTPS'] = 'on';
$_SERVER['SERVER_PORT'] = 443;
}
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
define('WP_HOME','https://www.xxx.com/');
define('WP_SITEURL','https://www.xxx.com/');
修改mysql数据
数据库: db_web, 表:wp_options, 字段option_name(值为siteurl,home)对应的option_value都为 https://www.xxx.com
docker stop ID
docker start ID
systemctl restart nginx