wordpress-建站实录


1、ecs 配置与系统调优

1. 阿里云 ecs 配置

选择阿里云 ecs 建站,当时正好有活动,3 年 100 块钱,系统 centos7.9 版本
阿里云官网,大家想买的话一定要关注最新活动,对新用户有优惠

ps: ecs 创建好之后记得把安全组入方向的 80 、443 的 tcp 端口打开

2. centos7 系统调优

2、解析 WordPress 网站域名

1. 创建新信息模板 (在注册域名之前需要创建信息模板)

  • 控制台搜索域名
  • 在左侧导航栏单击信息模板,在页面右上角单击创建新信息模板,然后根据界面提示,完成域名持有者信息填写,提交
  • 完成邮箱验证和实名验证
  • 最后模板状态为模板实名成功即可

2. 注册域名

  • 登录阿里云域名注册页在查询框中输入您想要的域名
  • 找个没有被注册过的域名加入购物车
  • 添加域名持有者信息并确认域名服务条款
  • 完成支付

3. 解析域名,将域名指向实例公网 IP

在左侧导航栏信息模板上方单击域名列表可以看到我们购买的域名

  • 点击解析
  • 点击新手引导 (不要点添加记录)
  • 记录值里填写 ecs 公网 IP 即可添加双域名
  • 确定

4. 备案

如果域名指向的网站托管在阿里云中国内地节点服务器,则需要进行备案

  • 在阿里云 ICP 代备案系统提交 ICP 备案申请
  • 提交之后阿里会先进行初审,我就是卡在网站名称这了,初审了 8 次才过,心态崩了(审核人员也崩了,他直接帮我改的名 - -! )
  • 初审通过后工信部短信核验 (24小时,又是一天过去了)
  • 工信部短信核验通过后管局还要审核 (6天左右)
  • 管局审核成功后,需要在网站首页底部中间位置放置您的ICP备案号并链接至"https://beian.miit.gov.cn"
打开个人站点-->仪表盘界面-->外观-->主题编辑器-->主题页脚 footer.php(右侧主题文件里面)-->在相应位置添加下方代码 (大概中间位置,多试试)

<!--带有工信部网站链接-->
<a href="<?php echo esc_url( __( 'https://beian.miit.gov.cn/', 'xicp' ) ); ?>" class="imprint">
<?php printf( __( '京ICP你的备案号', 'xicp' )); ?>
</a>
先注册账号-->登录账号-->点击主页 (会提示填写开办主体信息)-->进入(填写信息)
ps: 填写完毕保存草稿后会有提示弹出,安全评估报告先不管它!太麻烦而且还需要企业盖章!直接点击新办网站申请,具体怎么填,参见[公安联网备案信息填写指南]
(https://help.aliyun.com/document_detail/36981.htm?spm=a2c4g.11186623.0.0.189e13bdSRCmqo#concept-ukf-fsl-zdb)
  • 公安联网备案审核通过后,您需在 30 日内登录全国互联网安全管理服务平台,在您的已备案网站详情中,复制网站公安机关备案号和备案编号 HTML 代码,下载备案编号图标,并编辑您的网页源代码将公安联网备案信息放置在网页底部
ps: 我这边申请了一个月都没有通过,全是坑,不申请了

5. 申请 ssl 证书

  • 阿里云控制台里面找到 ssl 证书
  • 点击免费证书,有 20 个名额的证书可以创建
  • 等待证书为签发状态后下载 nginx 类型证书即可使用

3、lnmp 环境搭建

  1. nginx 安装与调优
  2. mysql 安装与调优
  3. php 安装与调优

4、搭建 WordPress 网站

1. mysql 建库

mysql -uroot -p

# 为 WordPress 网站创建数据库
create database wordpress;
# 创建一个新用户管理 WordPress 库,提高安全性
create user 'wordpress'@'localhost' identified by 'Wordpress123.';
# 赋予用户对数据库 wordpress 的全部权限
grant all privileges on wordpress.* to 'wordpress'@'localhost' identified by 'Wordpress123.';
# 使配置生效
flush privileges;
# 退出
exit;

2. wordpress 安装

  1. 下载 WordPress,并移动至网站根目录
cd /usr/local
tar zxf wordpress-5.8.2-zh_CN.tar.gz
mv /usr/local/wordpress /usr/local/nginx/html/wordpress
  1. 修改 WordPress 数据库配置文件
chown -R root.root /usr/local/nginx/html/wordpress
cd /usr/local/nginx/html/wordpress
cp wp-config-sample.php wp-config.php

vim wp-config.php

/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );
/** MySQL database username */
define( 'DB_USER', 'wordpress' );
/** MySQL database password */
define( 'DB_PASSWORD', 'Wordpress123.' );
/** MySQL hostname */
define( 'DB_HOST', 'localhost' );
/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );
  1. 修改Nginx配置文件 (主要是修改主目录)
    vim /usr/local/nginx/conf/extra/wordpress.conf
server {
    listen       80;
    server_name  haiqibiji.top;
    root    /usr/local/nginx/html/wordpress;

nginx -t && nginx -s reload
4. 访问域名验证
https://www.xx.com/

5、wordpress 调优

1、woedpress 后台管理页面

站点名/wp-admin

2、文章内图片放大功能添加

安装 Simple Lightbox 插件

3、新版 wordpress 编辑器换行

shift + 回车(Enter)键

4、favicon 在线制作

https://tool.lu/favicon/

5、将网站公网IP替换为新域名 (此步骤只针对 wordpress 安装在购买域名之前)

mysql -uroot -p

use wordpress;
select option_value from wp_options where option_name = 'home' OR option_name = 'siteurl';
+------------------------+
| option_value           |
+------------------------+
| http://123.456.187.123 |
| http://123.456.187.123 |
+------------------------+
2 rows in set (0.00 sec)
update wp_options set option_value = replace(option_value, 'http://实例公网IP', 'https://www.haiqibiji.top') where option_name = 'home' OR option_name = 'siteurl';

6、用户头像不显示

安装 Simple Local Avatars 插件
单击左侧菜单栏的用户,然后选择 Choose from Media Library,从本地选择对应的图片,更新个人资料后,确认头像显示成功

7、更新服务

在 WordPress 页面中,单击设置 > 撰写

http://rpc.pingomatic.com/
http://ping.baidu.com/ping/RPC2
http://blogsearch.google.com/ping/RPC2
http://api.my.yahoo.com/RPC2
http://api.my.yahoo.com/rss/ping
http://www.snipsnap.org/RPC2
http://xping.pubsub.com/ping
http://www.blogsdominicanos.com/ping/
http://www.feedsky.com/api/RPC2
http://blog.iask.com/RPC2
http://blog.youdao.com/ping/RPC2
http://rpc.twingly.com
http://api.feedster.com/ping
http://api.moreover.com/RPC2
http://api.moreover.com/ping
http://www.blogdigger.com/RPC2
http://www.blogshares.com/rpc.php
http://www.blogsnow.com/ping
http://www.blogstreet.com/xrbin/xmlrpc.cgi
http://bulkfeeds.net/rpc
http://www.newsisfree.com/xmlrpctest.php
http://ping.blo.gs/
http://ping.feedburner.com
http://ping.syndic8.com/xmlrpc.php
http://ping.weblogalot.com/rpc.php
http://rpc.blogrolling.com/pinger/
http://rpc.technorati.com/rpc/ping
http://rpc.weblogs.com/RPC2
http://www.feedsubmitter.com
http://blo.gs/ping.php
http://www.pingerati.net
http://www.pingmyblog.com
http://geourl.org/ping
http://ipings.com
http://www.weblogalot.com/ping

8、显示文章访问次数

安装 WP-PostViews 插件
WordPress 后台 > 设置 > 浏览次数,即可进入到 WP-PostViews 插件的设置页面,然后根据站点的实际情况配置
WordPress 后台 > 外观 > 主题文件编辑器 > 找到主题模板 (index.php) 文章页面 (single.php) 搜索结果 (search.php) 三个文件下面搜索关键字 have_posts
在关键字下面添加<?php if(function_exists('the_views')) { the_views(); } ?>即可看到效果

<?php if ( have_posts() ) : ?>
<?php if(function_exists('the_views')) { the_views(); } ?>

9、nginx 配置贴图

cat wordpress.conf

geo $ip_list {
    default 0;
    include /usr/local/nginx/conf/extra/ip_blacklist.txt;
}
server {
    listen       80;
    listen       443 ssl http2;
    server_name  haiqibiji.top;
    root    /usr/local/nginx/html/wordpress;
    if ($request_method !~ ^(GET|HEAD|POST)$) {        
      return 444;
    }
    if ($server_port = 80) {
      return 301 https://www.xx.com$request_uri;
    }
    if ( $ip_list = 1 ) {
    return 503;
    }
    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains;preload";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;
    add_header X-Frame-Options SAMEORIGIN;
    ssl_certificate  /usr/local/nginx/ssl/7150134_www.haiqibiji.top.pem;
    ssl_certificate_key  /usr/local/nginx/ssl/7150134_www.haiqibiji.top.key;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_protocols   TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers  on;
    ssl_session_tickets  off;
    ssl_session_cache  shared:SSL:1m;
    send_timeout                160;

    location / {
        index  index.html index.htmi index.php;
        #设置伪静态有利于搜索引擎收录网站
        if (-f $request_filename/index.html){
        rewrite (.*) $1/index.html break;
        }
        if (-f $request_filename/index.php){
        rewrite (.*) $1/index.php;
        }
        if (!-f $request_filename){
        rewrite (.*) /index.php;
        }
    }

    error_page   500 502 503 504 /50x/50x.html;
        location = /50x/50x.html {
    }
    error_page   404 /404/404.html;
    location = /404/404.html {
    }
    error_page   403 /403/403.html;
    location = /403/403.html {
    }

    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_pass    unix:/usr/local/php/php-fpm-cgi.sock;
        fastcgi_index   index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include         fastcgi_params;
        fastcgi_connect_timeout 180;
        fastcgi_send_timeout 180;
        fastcgi_read_timeout 180;
        fastcgi_buffer_size 64k;   
        fastcgi_buffers 4 32k;
        fastcgi_busy_buffers_size 64k;
        fastcgi_temp_file_write_size 64k;
    }
}

10、配置 markdown 支持

安装 WP Githuber MD 插件

6、wordpress 版本升级

1、获取最新的 WordPress zip(或 tar.gz)文件

https://wordpress.org/download/#download-install

cd /tmp
rz
tar zxf wordpress-5.9.1.tar.gz

2、停用插件

删除您的网络主机上的旧目录 wp-includes 和 wp-admin 目录
将新目录 wp-includes 和 wp-admi n目录上传到您的 Web 主机,以代替先前删除的目录
将新文件夹 wp-content 覆盖现有文件 wp-content ,不要删除现有 wp-content 目录中的任何文件或文件夹(被新文件覆盖的文件或文件夹除外)

cp:是否覆盖"./wp-content/index.php"? y
cp:是否覆盖"./wp-content/themes/index.php"? y
cp:是否覆盖"./wp-content/plugins/index.php"? y
将新版本根目录中的所有新松散文件上传到您现有的 WordPress 根目录
cp:是否覆盖"./index.php"? y
cp:是否覆盖"./license.txt"? y
cp:是否覆盖"./readme.html"? y
cp:是否覆盖"./wp-activate.php"? y
cp:是否覆盖"./wp-blog-header.php"? y
cp:是否覆盖"./wp-comments-post.php"? y
cp:是否覆盖"./wp-config-sample.php"? y
cp:是否覆盖"./wp-cron.php"? y
cp:是否覆盖"./wp-links-opml.php"? y
cp:是否覆盖"./wp-load.php"? y
cp:是否覆盖"./wp-login.php"? y
cp:是否覆盖"./wp-mail.php"? y
cp:是否覆盖"./wp-settings.php"? y
cp:是否覆盖"./wp-signup.php"? y
cp:是否覆盖"./wp-trackback.php"? y
cp:是否覆盖"./xmlrpc.php"? y

请使用 FTP 从 WordPress 目录中删除文件.maintenance 这将删除“更新失败”的唠叨消息
在 /wp-admin 访问您的 WordPress 主管理页面
如果此时需要升级数据库,WordPress 会检测到它并为您提供指向类似 http://example.com/wordpress/wp-admin/upgrade.php. 按照该链接并按照说明进行操作。
这将更新您的数据库以与最新代码兼容。您应该在第 1 步之后尽快执行此操作。
不要忘记重新激活插件!

             ------------------------------- THE END -------------------------------

posted @ 2025-02-13 17:41  ordinaryRoadX  阅读(4)  评论(0编辑  收藏  举报