0%

wordpress配置技巧

1. 安装插件需要ftp

Wordpress安装主题或者插件的时候会遇到需要输入FTP的情况,这种情况是由于网站目录权限引起的。

  1. 在wp-config.php文件添加以下代码:
1
define('FS_METHOD','direct');
  1. 修改wp安装目录权限
1
2
chmod -R 755 /var/www/wordpress/
chown -R nobody:nobody /var/www/wordpress/ # 不知道用户可以把目录权限改成777

2. 配置 https

  1. 使用腾讯云免费1年的证书(域名)

  2. 配置 nginx

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    server {
    listen 80;
    listen [::]:80;
    server_name httprun.com www.httprun.com;
    return 301 https://www.httprun.com$request_uri;
    }


    server {
    listen 443;
    listen [::]:443;
    server_name httprun.com www.httprun.com;

    ssl on;
    ssl_certificate /etc/nginx/ssl/wordpress/1_www.httprun.com_bundle.crt;
    ssl_certificate_key /etc/nginx/ssl/wordpress/2_www.httprun.com.key;
    ssl_session_timeout 5m;
    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE;
    ssl_prefer_server_ciphers on;

    root /var/www/wordpress/;

    location / {
    index index.html index.htm index.php;
    }

    location ~ \.php {
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
    }
    }
  1. 进入WP后台,进入设置-常规 将WordPress地址(URL)、站点地址(URL)两项修改为:https。

    1

  1. 登录和后台强制开启SSL, 修改WP-config.php文件

    1
    2
    define('FORCE_SSL_LOGIN', true);
    define('FORCE_SSL_ADMIN', true);
  2. 修改数据库的历史 url

    1
    update wp_posts set post_content = replace(post_content, 'http://www.httprun.com','https://www.httprun.com');

3. 插件

3.1 腾讯云cos

3.2 备份网站

updraftplus 关键时刻会救命,会备份数据库,插件和主题等等。

  • 恢复的时候sql datetime默认值问题
1
0000-00-00 00:00:00   修改为  0000-01-01 00:00:00

3.3 安全插件

Wordfence

3.4 显示访问次数

WP-PostViews

4. 错误解决

4.1 上传图片失败

  • 最大上传限制

    https://wordpress.org/plugins/upload-max-file-size/

    看接口:wp-admin/async-upload.php,413 Request Entity Too Large,修改nginx 增加client_max_body_size

    1
    2
    3
    4
    5
    6
    7
    server {
    listen 443;
    listen [::]:443;
    .....
    client_max_body_size 128m;
    .....
    }
  • 上传的文件大小超过php.ini文件中定义的upload_max_filesize值。

    如果是 php-fpm 方式运行,启动php-fpm 通过参数 -c 指定配置文件即可。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    [Unit]
    Description=The PHP FastCGI Process Manager
    After=syslog.target network.target

    [Service]
    Type=forking
    PIDFile=/usr/local/php8/var/run/php-fpm.pid
    ExecStart=/usr/local/php8/sbin/php-fpm -c /usr/local/php8/etc/php.ini
    ExecReload=/bin/kill -USR2 $MAINPID
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

    vi /usr/local/php8/etc/php.ini

    1
    2
    upload_max_filesize = 512M
    post_max_size = 512M

5. 其他问题

5.1 备案

复制以下代码,备案号改成自己的。然后把代码放到后台->主题->主题编辑器的footer.php里面

1
2
3
4
5
6
7
<div style="text-align: center">
<p style="float:center;height:20px;line-height:20px;margin: 10px 0px 10px 0px;color:#737373;">Copyright @2021 版权所有
<a target="_blank" href="https://beian.miit.gov.cn/" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
<img src="https://s1.ax1x.com/2020/07/02/NqYHbQ.png" style="float:left;"/>京ICP备xxxxx号
</a>
</p>
</div>

5.2 更换域名

  • 把域名的解析和证书先彻底换掉
  • wp_options 这个数据表, 寻找 siteurl 和 home, 修改新域名。

6. 参考资料

给作者打赏,可以加首页微信,咨询作者相关问题!