一台云服务器Windows篇:09、WordPress

php、Nginx、DB都已经运行正常的情况下,WordPress 6.7 的安装与配置。

系统需求:Server Environment – Make WordPress Hosting

安装

前提:php、Nginx、DB都已经运行正常了。

配置php扩展

在php.ini中开启以下扩展,并重启php-cgi或xxfpm生效(PHP 要求:Server Environment):

extension=curl
extension=gd
extension=intl
extension=mbstring
extension=mysqli
extension=openssl
extension=zip

配置MariaDB/MySQL

创建db与用户、授权

CREATE DATABASE IF NOT EXISTS WordPress DEFAULT CHARSET utf8;
CREATE USER 'wp_xxx'@'localhost' IDENTIFIED BY 'xxxxx';
GRANT all privileges ON WordPress.* TO 'wp_xxx'@'localhost';
flush privileges;

配置nginx

Nginx
    server {
        listen       80;
        server_name  y.z www.y.z;
        # 自动跳转https
        return 301 https://y.z$request_uri;
    }
    server {
        listen       443 ssl;
        server_name  y.z;
        # 相对路径 cert/xxx.pem,为在conf目录中
        ssl_certificate      cert/y.z-crt.pem;
        ssl_certificate_key  cert/y.z-key.pem;
        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;
        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        if ($time_iso8601 ~ "^(\d{4})-(\d{2})") {
            set $year $1;
            set $month $2;
        }
        access_log  logs/access-$year$month-$host.log main;
        
        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        location ~ \.php$ { 
            root C:/webRoot/WordPress; 
            fastcgi_pass 127.0.0.1:9000;   
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;  
            include fastcgi_params;
        }
        
        location / {
            root   C:/webRoot/WordPress; 
            index  index.php index.html index.htm;
        }

        # SSL证书验证: root是相对路径 alias 是绝对路径,验证程序会在root目录下创建[.well-known/acme-challenge/xxx]文件,以[y.z/.well-known/acme-challenge/xxx]访问。
        location ^~ /.well-known/acme-challenge/ {
            default_type "text/plain";
            root certVerify_y-z;
        }

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

开始安装WordPress

浏览器中访问:y.z/wp-admin/install.php,安装过程很简单。

Db不是标准端口:需要修改DB_HOST的值,格式为 localhost:33060

WordPress配置

固定链接

建议使用 /archives/%xxx%/ 之类,有了/archives/固定前缀,方便以后在Nginx中配置区别。

注意:wordpress 固定链接功能,改为默认设置后,需要调整Nginx转发规则,否则访问文章会有402报错。

        location / {
            root   C:/webData/WordPress;
            index  index.php index.html index.htm;
            # WordPress 固定链接功能支持
            try_files $uri $uri/ /index.php?$args;
        }

禁用修订版本、禁用自动保存

打开 wp-config.php 文件,在 $table_prefix = ‘xxxx’; 这行的下面添加内容:

define('WP_POST_REVISIONS', false);   //禁用历史修订版本,也可以填数字,就是保存几个版本
define('AUTOSAVE_INTERVAL', 86400);   //设置自动保存时间设置为一天(相当于关闭了)

插件:WP-China-Yes [新手推荐,折腾后之可以删除了]

下载:软件下载 – 文派叶子 🍃(WP-China-Yes)

上传服务器,解压后的目录,移到WordPress/wp-content/plugins/目录中。再到WEB后台“已安装播件”中启用,就可以了进入设置了。

插件:Simple Local Avatars [可选]

WP的头像是Gravatar提供的,国内使用访问不了。这个插件让WP用户使用上传图片为头像,或者到WP-China-Yes支持源中注册自己的头像。

另外,默认用户的头像,WP自身就支持上传图片。

插件:WP Mail SMTP 或商店搜索SMTP[必备]

  1. 准备好 noreply@xxx.xxx 的SMTP信息
  2. 阿里云帮助:如何配置域名的SPF解析以避免退信什么是DMARC,DMARC 如何设置? 什么是DKIM,如何添加DKIM?
  3. WP Mail SMTP 配置:
    1. WEB管理后台里,在插件中配置的发件人地址,与登录人地址,要使用同一个邮箱账号。
    2. 使用WP常量方式保护SMTP配置:Securing SMTP Settings With Constants – WP Mail SMTP

在 wp-config.php 中的 /* That’s all, stop editing! Happy publishing. */ 行上面,添加以下内容:

JavaScript
/* Enable WP Mail SMTP Constants  
 * 
 * Original doc: https://wpmailsmtp.com/docs/how-to-secure-smtp-settings-by-using-constants/
*/
define( 'WPMS_ON', true );

define( 'WPMS_LICENSE_KEY', '' ); 
define( 'WPMS_MAIL_FROM', 'noreply@t725.cn' );
define( 'WPMS_MAIL_FROM_FORCE', true ); // True turns it on, false turns it off.
define( 'WPMS_MAIL_FROM_NAME', 'noreply' );
define( 'WPMS_MAIL_FROM_NAME_FORCE', true ); // True turns it on, false turns it off.
define( 'WPMS_MAILER', 'smtp' ); // Possible values: 'mail', 'gmail', 'mailgun', 'sendgrid', 'smtp'.
define( 'WPMS_SET_RETURN_PATH', true ); // Sets $phpmailer->Sender if true.
define( 'WPMS_DO_NOT_SEND', false ); // Possible values: true, false.

define ( 'WPMS_LOGS_ENABLED', true ); // True turns it on, false turns it off.
define ( 'WPMS_LOGS_LOG_EMAIL_CONTENT', true ); // True turns it on and stores email content, false turns it off.
define ( 'WPMS_LOGS_LOG_RETENTION_PERIOD', 604800 ); // How long email logs should be retained before they are deleted, in seconds. To disable the log retention period and keep logs forever, set to 0.

define( 'WPMS_SMTP_HOST', 'smtp.qiye.aliyun.com' ); // The SMTP mail host.
define( 'WPMS_SMTP_PORT', 465 ); // The SMTP server port number.
define( 'WPMS_SSL', 'ssl' ); // Possible values '', 'ssl', 'tls' - note TLS is not STARTTLS.
define( 'WPMS_SMTP_AUTOTLS',false  ); // True turns it on, false turns it off.
define( 'WPMS_SMTP_AUTH', true ); // True turns it on, false turns it off.
define( 'WPMS_SMTP_USER', 'noreply@t725.cn' ); // SMTP authentication username, only used if WPMS_SMTP_AUTH is true.
define( 'WPMS_SMTP_PASS', '密码' ); // SMTP authentication password, only used if WPMS_SMTP_AUTH is true.

插件:LuckyWP Table of Contents 或商店搜索Table of Contents

如何在 WordPress 文章中创建内容目录 – WordPress大学

自动插入目录配置

默认关闭,开启后可以配置哪些类型自动插入

手工插入目录方法

先可以配置哪些类型可以手工插入目录

再在具体类型的区块编辑上,点击启用目录

WordPress 区块编辑器使用

  1. 主题在商店挑自己喜欢的就可以了,但有主题在首页或列表页面,对于文章显示是全部内容,需要设置为显示摘要
  2. 区块编辑器在段落里,enter是添新区块,而shit+enter是换段落。
  3. 编辑器里区域之间间距很小,可以通过间隔来调整。
  1. 区域编辑器UI设置

sitemap 与 robots.txt

wordpress已经内置站点地图功能,通过访问/robots.txt,就可以看到Sitemap的URL。/robots.txt 内容默认是动态管理,也可以直接上传/robots.txt文件替代,比如:

User-agent: *
Disallow: /wp-admin/
Allow: /wp-admin/admin-ajax.php
Disallow: /wp-content/
Allow: /wp-content/uploads/20
Disallow: /wp-includes/
Disallow: /?s=

Sitemap: https://blog.t725.cn/wp-sitemap.xml

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注