时间:2022-08-11 01:42:01 | 来源:网站运营
时间:2022-08-11 01:42:01 来源:网站运营
本文不讲废话,现在就开始教你一步步搭建自己的网站,下面大家可以看一下我花费半小时搭建出来自己的博客网站 zempty 笔记sudo yum install -y yum-utils device-mapper-persistent-data lvm2sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.reposudo yum install -y docker-ce docker-ce-cli containerd
systemctl start docker
systemctl status docker
mkdir -p ~/software/mysql/conf ~/software/mysql/logs ~software/mysql/data
远程拉取 mysql 的数据库docker pull mysql首先运行一个实例:docker run -it -d -- name mysql -e MYSQL_ROOT_PASSWORD=123456 mysql复制该实例的配置文件到 server 当中:docker cp mysql:/etc/mysql/conf.d ~software/mysql/conf 删除旧的实例:docker rm -f mysql重新创建一个 mysql 容器:docker run -it -d --name mysql -p 3306:3306 -v ~/software/mysql/conf:/etc/mysql/conf.d -v ~/software/mysql/logs:/logs -v ~/software/mysql/data:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=123456 mysql查看容器是否创建成功:docker ps如果有列出 mysql ,证明你的 mysql 安装成功了 !!!
docker exec -it mysql mysql -uroot -p
输入密码进入数据库即可。use mysql;
修改数据库 user 表进行远程连接:ALTER USER 'root'@'%' IDENTIFIED WITH mysql_native_password BY '123456';
刷新修改:flush privileges;
远程仓库拉取 wordpress:docker pull wordpress先运行一个 wordpress 实例:docker run -it -d --name wordpress --link mysql:mysql -p 9001:80 wordpress 复制现有的 wordpress 文件到当前 server :docker cp wordpress:/var/www/html ~/software/wordpress删除刚安装的容器:docker rm -f wordpress重新安装 wordpress 容器:docker run -it -d --name wordpress -p 9001:80 -v ~software/wordpress/:/var/www/html --link mysql:mysql wordpress
RewriteEngine OnRewriteBase /RewriteRule ^index/.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]#增加如下两行配置上传文件的大小php_value post_max_size 24Mphp_value upload_max_filesize 8M
重启 wordpress :docker restart wordpress
远程仓库拉取 nginx:docker pull nginx 先运行一个 nginx 的容器:docker run -it -d --name nginx nginx复制配置文件:docker cp nginx:/etc/nginx/ ~/software/删除 nginx 的容器:docker rm -f nginx重新建立一个 nginx 的容器:docker run -it -d --name nginx-v ~/software/nginx/:/etc/nginx/-v ~/software/nginx/logs:/var/log/nginx/ -v ~/software/nginx/www/:/usr/share/nginx/html/ -p 80:80 nginx查看 nginx 是否正常运行:docker ps 看一下运行的服务当中是否有 nginx , 有,恭喜你 ,nginx 安装成功了!!!
vim ~/software/nginx/conf.d/default.conf
server { listen 80 default_server; listen [::]:80 default_server; server_name zempty.sg www.zempty.sg # Load configuration files for the default server block. include /etc/nginx/default.d/*.conf; location / { proxy_pass http://zempty.sg:9001/; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } }
docker run -it -d --name nginx-v ~/software/nginx/:/etc/nginx/-v ~/software/nginx/logs:/var/log/nginx/ -v ~/software/nginx/www/:/usr/share/nginx/html/-p 80:80 -p 443:443nginx
yum install git
git clone git@github.com:certbot/certbot.git
cd ~/software/certbot
docker stop nginx
./certbot-auto certonly -m kickcodeman@qq.com -d zempty.cf -d www.zempty.cf
解释一下上面命令的几个参数: -m 后面是自己的邮箱, -d 后面的自己的域名,一般有两个,按照屏幕提示一步步操作下去最终在 /etc//etc/letsencrypt/live/个人域名目录/ 下面会有 fullchain.pem 和 privkey.pem 两个文件.cp /etc/letsencrypt/live/个人域名目录/fullchain.pem ~/software/nginxcp /etc/letsencrypt/live/个人域名目录/privkey.pem ~/software/nginx
cd ~/software/nginx/conf.d
打开配置文件作如下配置: vim default.conf
配置文件修改如下:server { listen 80 default_server; server_name zempty.cf www.zempty.cf; return 301 https://$server_name$request_uri; } server { listen 443 ssl; server_name zempty.cf www.zempty.cf; ssl_certificate fullchain.pem; ssl_certificate_key privkey.pem; ssl_session_cache shared:SSL:1m; ssl_session_timeout 5m; ssl_ciphers HIGH:!aNULL:!MD5; ssl_prefer_server_ciphers on; autoindex on; location / { proxy_pass http://zempty.cf:9001; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
docker restart nginx
请打开你的浏览器输入你的域名 www.zempty.cf ,可以看到 https 访问网站成功,关键词:详细,学习