本篇是《手动部署php——软件包安装》的后续。
在已经完成的nginx,mysql和php安装的情况,可以手动配置安装wordpress了,以验证以上环境搭建的情况。需要了解nginx和mysql以及php安装的请见以下说明:
安装wordpress需要配置的文件,可以参考一下设置。
- 设定wordpress的文件位置
cd /opt ll wget https://cn.wordpress.org/latest-zh_CN.tar.gz tar -zxvf latest-zh_CN.tar.gz cd wordpress cp wp-config-sample.php wp-config.php nano wp-config.php
配置wordpress与mysql的连接:
- 设定nginx和网站配置文件
打开nginx.conf
nano /etc/nginx/nginx.conf
查看
因此在/etc/nginx/conf.d/目录下新建wordpress.conf
nano /etc/nginx/conf.d/wordpress.conf
放置以下内容:
# # The default server # server { listen 80; server_name test.fanlog.xyz; #charset koi8-r; #access_log logs/host.access.log main; location / { root /opt/wordpress; index index.php index.html index.htm; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /opt/wordpress; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} }
测试nginx设置:
nginx -t
重启nginx,使得配置生效
systemctl restart nginx
- 打开网址进行安装wordpress
进入后台:
- 赋予wordpress目录权限
cd /opt/wordpress chown nginx:nginx * -R usermod -a -G nginx username
- 发布一篇新博客
- 部署SSL,详细见此centos7 安装Let’s Encrypt证书
停止nginx
systemctl stop nginx
安装自动获取证书服务
cd ~ yum install certbot certbot certonly --standalone -w /var/www/test.fanlog.xyz -d test.fanlog.xyz
效果如下:
重新配置nginx的配置文件wordpress.conf
效果如下:
- 强制开启ssl转换
参考的最终wordpress.conf:wordpress2
- wordpress伪静态
- 后续工作
- 设置php插件
- 设置firewall+fail2ban,见centos7/8 安装denyhosts防止SSH破解
- 关闭默认ssh账号,见linux创建root权限用户并禁用root登录
- 验证过的vps
- vutrl
- aws lightsail
参考资料:
- https://my.oschina.net/u/1861878/blog/3098693
- https://www.linuxprobe.com/install-wordpress-nginx.html
- https://juejin.im/post/6844904100589469703