在使用WordPress写文章的时候,如果使用H5及以下字体,英文字母会被强制转换成大写,导致布局非常难看。
解决方法是通过覆盖默认的 text-transform属性,如下:
1 |
<h5 style="text-transform: none;">1.JavaScriptCore</h5> |
使用PHP语言开发的博客平台,支持在PHP和MySQL的服务器上架设自己的博客
在使用WordPress写文章的时候,如果使用H5及以下字体,英文字母会被强制转换成大写,导致布局非常难看。
解决方法是通过覆盖默认的 text-transform属性,如下:
1 |
<h5 style="text-transform: none;">1.JavaScriptCore</h5> |
以前通过 家里ADSL上网无固定外网IP的群晖NAS安全实现与公网MySQL服务器主从同步 配置之后,群晖自带的 MariaDB 10.3.21 可以非常流畅的与服务器上的 MySQL 7.x 版本进行主从同步。
前两天系统从 ubuntu 18.04 升级到 ubuntu 20.04 (MySQL 8.x)之后,发现已经无法进行主从同步。
报告如下错误:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
$ mysql -u root -p -e "show slave status\G;" Enter password: *************************** 1. row *************************** Slave_IO_State: Master_Host: 10.8.0.1 Master_User: repl1 Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysql-bin.001242 Read_Master_Log_Pos: 8350259 Relay_Log_File: mysqld10-relay-bin.000510 Relay_Log_Pos: 424 Relay_Master_Log_File: mysql-bin.001222 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 22 Last_Error: Error 'Character set '#255' is not a compiled character set and is not specified in the '/usr/local/mariadb10/share/mysql/charsets/Index.xml' file' on query. Default database: 'wordpress'. Query: 'BEGIN' Skip_Counter: 0 Exec_Master_Log_Pos: 125 Relay_Log_Space: 137841279 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: Yes Master_SSL_CA_File: /var/packages/MariaDB10/etc/ssl/ca.pem Master_SSL_CA_Path: /var/packages/MariaDB10/etc/ssl Master_SSL_Cert: /var/packages/MariaDB10/etc/ssl/client-cert.pem Master_SSL_Cipher: Master_SSL_Key: /var/packages/MariaDB10/etc/ssl/client-key.pem Seconds_Behind_Master: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 22 Last_SQL_Error: Error 'Character set '#255' is not a compiled character set and is not specified in the '/usr/local/mariadb10/share/mysql/charsets/Index.xml' file' on query. Default database: 'wordpress'. Query: 'BEGIN' Replicate_Ignore_Server_Ids: Master_Server_Id: 1 Master_SSL_Crl: /var/packages/MariaDB10/etc/ssl/ca.pem Master_SSL_Crlpath: /var/packages/MariaDB10/etc/ssl Using_Gtid: No Gtid_IO_Pos: Replicate_Do_Domain_Ids: Replicate_Ignore_Domain_Ids: Parallel_Mode: conservative SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave_DDL_Groups: 0 Slave_Non_Transactional_Groups: 0 Slave_Transactional_Groups: 0 |
网上查询很久,找到原因 MySQL 8.016 master with MariaDB 10.2 slave on AWS RDS, Character set '#255' is not a compiled character set
This could be a serious problem when replicating between MySQL 8.0 and MariaDB 10.x.
The default (for good technical reasons) COLLATION
for the 8.0 is utf8mb4_0900_ai_ci
. Note the "255" associated with it. MariaDB has not yet adopted the Unicode 9.0 collations.
Furthermore, Oracle (MySQL 8.0) did a major rewrite of the collation code, thereby possibly making collation tables incompatible.
A probable fix is to switch to the next best general-purpose collation, utf8mb4_unicode_520_ci
(246) (based on Unicode 5.20). This would require ALTERing
all the columns' collations. ALTER TABLE .. CONVERT TO ..
might be the fastest way. Those could be generated via a SELECT .. information_schema.tables ...
.
大致原因就是MySql 8.0默认使用了最新的utf8mb4_0900_ai_ci字符集,然而MariaDB 10.3.x版本不支持这个字符集,导致无法同步。
8.0.17:
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
mysql> show collation like 'utf8mb4%'; +----------------------------+---------+-----+---------+----------+---------+---------------+ | Collation | Charset | Id | Default | Compiled | Sortlen | Pad_attribute | +----------------------------+---------+-----+---------+----------+---------+---------------+ | utf8mb4_0900_ai_ci | utf8mb4 | 255 | Yes | Yes | 0 | NO PAD | | utf8mb4_0900_as_ci | utf8mb4 | 305 | | Yes | 0 | NO PAD | | utf8mb4_0900_as_cs | utf8mb4 | 278 | | Yes | 0 | NO PAD | | utf8mb4_0900_bin | utf8mb4 | 309 | | Yes | 1 | NO PAD | | utf8mb4_bin | utf8mb4 | 46 | | Yes | 1 | PAD SPACE | | utf8mb4_croatian_ci | utf8mb4 | 245 | | Yes | 8 | PAD SPACE | | utf8mb4_cs_0900_ai_ci | utf8mb4 | 266 | | Yes | 0 | NO PAD | | utf8mb4_cs_0900_as_cs | utf8mb4 | 289 | | Yes | 0 | NO PAD | | utf8mb4_czech_ci | utf8mb4 | 234 | | Yes | 8 | PAD SPACE | | utf8mb4_danish_ci | utf8mb4 | 235 | | Yes | 8 | PAD SPACE | | utf8mb4_da_0900_ai_ci | utf8mb4 | 267 | | Yes | 0 | NO PAD | | utf8mb4_da_0900_as_cs | utf8mb4 | 290 | | Yes | 0 | NO PAD | | utf8mb4_de_pb_0900_ai_ci | utf8mb4 | 256 | | Yes | 0 | NO PAD | | utf8mb4_de_pb_0900_as_cs | utf8mb4 | 279 | | Yes | 0 | NO PAD | | utf8mb4_eo_0900_ai_ci | utf8mb4 | 273 | | Yes | 0 | NO PAD | | utf8mb4_eo_0900_as_cs | utf8mb4 | 296 | | Yes | 0 | NO PAD | | utf8mb4_esperanto_ci | utf8mb4 | 241 | | Yes | 8 | PAD SPACE | | utf8mb4_estonian_ci | utf8mb4 | 230 | | Yes | 8 | PAD SPACE | | utf8mb4_es_0900_ai_ci | utf8mb4 | 263 | | Yes | 0 | NO PAD | | utf8mb4_es_0900_as_cs | utf8mb4 | 286 | | Yes | 0 | NO PAD | | utf8mb4_es_trad_0900_ai_ci | utf8mb4 | 270 | | Yes | 0 | NO PAD | | utf8mb4_es_trad_0900_as_cs | utf8mb4 | 293 | | Yes | 0 | NO PAD | | utf8mb4_et_0900_ai_ci | utf8mb4 | 262 | | Yes | 0 | NO PAD | | utf8mb4_et_0900_as_cs | utf8mb4 | 285 | | Yes | 0 | NO PAD | | utf8mb4_general_ci | utf8mb4 | 45 | | Yes | 1 | PAD SPACE | | utf8mb4_german2_ci | utf8mb4 | 244 | | Yes | 8 | PAD SPACE | | utf8mb4_hr_0900_ai_ci | utf8mb4 | 275 | | Yes | 0 | NO PAD | | utf8mb4_hr_0900_as_cs | utf8mb4 | 298 | | Yes | 0 | NO PAD | | utf8mb4_hungarian_ci | utf8mb4 | 242 | | Yes | 8 | PAD SPACE | | utf8mb4_hu_0900_ai_ci | utf8mb4 | 274 | | Yes | 0 | NO PAD | | utf8mb4_hu_0900_as_cs | utf8mb4 | 297 | | Yes | 0 | NO PAD | | utf8mb4_icelandic_ci | utf8mb4 | 225 | | Yes | 8 | PAD SPACE | | utf8mb4_is_0900_ai_ci | utf8mb4 | 257 | | Yes | 0 | NO PAD | | utf8mb4_is_0900_as_cs | utf8mb4 | 280 | | Yes | 0 | NO PAD | | utf8mb4_ja_0900_as_cs | utf8mb4 | 303 | | Yes | 0 | NO PAD | | utf8mb4_ja_0900_as_cs_ks | utf8mb4 | 304 | | Yes | 24 | NO PAD | | utf8mb4_latvian_ci | utf8mb4 | 226 | | Yes | 8 | PAD SPACE | | utf8mb4_la_0900_ai_ci | utf8mb4 | 271 | | Yes | 0 | NO PAD | | utf8mb4_la_0900_as_cs | utf8mb4 | 294 | | Yes | 0 | NO PAD | | utf8mb4_lithuanian_ci | utf8mb4 | 236 | | Yes | 8 | PAD SPACE | | utf8mb4_lt_0900_ai_ci | utf8mb4 | 268 | | Yes | 0 | NO PAD | | utf8mb4_lt_0900_as_cs | utf8mb4 | 291 | | Yes | 0 | NO PAD | | utf8mb4_lv_0900_ai_ci | utf8mb4 | 258 | | Yes | 0 | NO PAD | | utf8mb4_lv_0900_as_cs | utf8mb4 | 281 | | Yes | 0 | NO PAD | | utf8mb4_persian_ci | utf8mb4 | 240 | | Yes | 8 | PAD SPACE | | utf8mb4_pl_0900_ai_ci | utf8mb4 | 261 | | Yes | 0 | NO PAD | | utf8mb4_pl_0900_as_cs | utf8mb4 | 284 | | Yes | 0 | NO PAD | | utf8mb4_polish_ci | utf8mb4 | 229 | | Yes | 8 | PAD SPACE | | utf8mb4_romanian_ci | utf8mb4 | 227 | | Yes | 8 | PAD SPACE | | utf8mb4_roman_ci | utf8mb4 | 239 | | Yes | 8 | PAD SPACE | | utf8mb4_ro_0900_ai_ci | utf8mb4 | 259 | | Yes | 0 | NO PAD | | utf8mb4_ro_0900_as_cs | utf8mb4 | 282 | | Yes | 0 | NO PAD | | utf8mb4_ru_0900_ai_ci | utf8mb4 | 306 | | Yes | 0 | NO PAD | | utf8mb4_ru_0900_as_cs | utf8mb4 | 307 | | Yes | 0 | NO PAD | | utf8mb4_sinhala_ci | utf8mb4 | 243 | | Yes | 8 | PAD SPACE | | utf8mb4_sk_0900_ai_ci | utf8mb4 | 269 | | Yes | 0 | NO PAD | | utf8mb4_sk_0900_as_cs | utf8mb4 | 292 | | Yes | 0 | NO PAD | | utf8mb4_slovak_ci | utf8mb4 | 237 | | Yes | 8 | PAD SPACE | | utf8mb4_slovenian_ci | utf8mb4 | 228 | | Yes | 8 | PAD SPACE | | utf8mb4_sl_0900_ai_ci | utf8mb4 | 260 | | Yes | 0 | NO PAD | | utf8mb4_sl_0900_as_cs | utf8mb4 | 283 | | Yes | 0 | NO PAD | | utf8mb4_spanish2_ci | utf8mb4 | 238 | | Yes | 8 | PAD SPACE | | utf8mb4_spanish_ci | utf8mb4 | 231 | | Yes | 8 | PAD SPACE | | utf8mb4_sv_0900_ai_ci | utf8mb4 | 264 | | Yes | 0 | NO PAD | | utf8mb4_sv_0900_as_cs | utf8mb4 | 287 | | Yes | 0 | NO PAD | | utf8mb4_swedish_ci | utf8mb4 | 232 | | Yes | 8 | PAD SPACE | | utf8mb4_tr_0900_ai_ci | utf8mb4 | 265 | | Yes | 0 | NO PAD | | utf8mb4_tr_0900_as_cs | utf8mb4 | 288 | | Yes | 0 | NO PAD | | utf8mb4_turkish_ci | utf8mb4 | 233 | | Yes | 8 | PAD SPACE | | utf8mb4_unicode_520_ci | utf8mb4 | 246 | | Yes | 8 | PAD SPACE | | utf8mb4_unicode_ci | utf8mb4 | 224 | | Yes | 8 | PAD SPACE | | utf8mb4_vietnamese_ci | utf8mb4 | 247 | | Yes | 8 | PAD SPACE | | utf8mb4_vi_0900_ai_ci | utf8mb4 | 277 | | Yes | 0 | NO PAD | | utf8mb4_vi_0900_as_cs | utf8mb4 | 300 | | Yes | 0 | NO PAD | | utf8mb4_zh_0900_as_cs | utf8mb4 | 308 | | Yes | 0 | NO PAD | +----------------------------+---------+-----+---------+----------+---------+---------------+ 75 rows in set (0.01 sec) |
MariaDB 10.2.30:
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 35 36 37 38 39 |
mysql> SHOW COLLATION LIKE 'utf8mb4%'; +------------------------------+---------+------+---------+----------+---------+ | Collation | Charset | Id | Default | Compiled | Sortlen | +------------------------------+---------+------+---------+----------+---------+ | utf8mb4_general_ci | utf8mb4 | 45 | Yes | Yes | 1 | | utf8mb4_bin | utf8mb4 | 46 | | Yes | 1 | | utf8mb4_unicode_ci | utf8mb4 | 224 | | Yes | 8 | | utf8mb4_icelandic_ci | utf8mb4 | 225 | | Yes | 8 | | utf8mb4_latvian_ci | utf8mb4 | 226 | | Yes | 8 | | utf8mb4_romanian_ci | utf8mb4 | 227 | | Yes | 8 | | utf8mb4_slovenian_ci | utf8mb4 | 228 | | Yes | 8 | | utf8mb4_polish_ci | utf8mb4 | 229 | | Yes | 8 | | utf8mb4_estonian_ci | utf8mb4 | 230 | | Yes | 8 | | utf8mb4_spanish_ci | utf8mb4 | 231 | | Yes | 8 | | utf8mb4_swedish_ci | utf8mb4 | 232 | | Yes | 8 | | utf8mb4_turkish_ci | utf8mb4 | 233 | | Yes | 8 | | utf8mb4_czech_ci | utf8mb4 | 234 | | Yes | 8 | | utf8mb4_danish_ci | utf8mb4 | 235 | | Yes | 8 | | utf8mb4_lithuanian_ci | utf8mb4 | 236 | | Yes | 8 | | utf8mb4_slovak_ci | utf8mb4 | 237 | | Yes | 8 | | utf8mb4_spanish2_ci | utf8mb4 | 238 | | Yes | 8 | | utf8mb4_roman_ci | utf8mb4 | 239 | | Yes | 8 | | utf8mb4_persian_ci | utf8mb4 | 240 | | Yes | 8 | | utf8mb4_esperanto_ci | utf8mb4 | 241 | | Yes | 8 | | utf8mb4_hungarian_ci | utf8mb4 | 242 | | Yes | 8 | | utf8mb4_sinhala_ci | utf8mb4 | 243 | | Yes | 8 | | utf8mb4_german2_ci | utf8mb4 | 244 | | Yes | 8 | | utf8mb4_croatian_mysql561_ci | utf8mb4 | 245 | | Yes | 8 | | utf8mb4_unicode_520_ci | utf8mb4 | 246 | | Yes | 8 | <-- | utf8mb4_vietnamese_ci | utf8mb4 | 247 | | Yes | 8 | | utf8mb4_croatian_ci | utf8mb4 | 608 | | Yes | 8 | | utf8mb4_myanmar_ci | utf8mb4 | 609 | | Yes | 8 | | utf8mb4_thai_520_w2 | utf8mb4 | 610 | | Yes | 4 | | utf8mb4_general_nopad_ci | utf8mb4 | 1069 | | Yes | 1 | | utf8mb4_nopad_bin | utf8mb4 | 1070 | | Yes | 1 | | utf8mb4_unicode_nopad_ci | utf8mb4 | 1248 | | Yes | 8 | | utf8mb4_unicode_520_nopad_ci | utf8mb4 | 1270 | | Yes | 8 | +------------------------------+---------+------+---------+----------+---------+ 33 rows in set (0.00 sec) |
目前暂时没打算修改主服务器上的数据库,暂时等 MariaDB 更新吧。
在新版的WordPress中,系统已经多次提示升级PHP,考虑到新版本更高效更安全,所以决定升级。
可是,升级完成后,网站出现大量报错,报错信息如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 Warning: preg_replace(): Compilation failed: invalid range in character class at offset 4 in /var/www/wordpress/wp-content/plugins/crayon-syntax-highlighter/crayon_langs.class.php on line 340 |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
$ sudo apt-get install apache2 $ sudo apt-get install mysql-server $ sudo apt-get install mysql-client $ sudo apt-get install php7.2 $ sudo apt-get install php-gd $ sudo apt install php-mbstring $ sudo apt install php-dom # 如果使用了WP-Statistics统计插件,需要安装依赖 $ sudo apt-get install php7.2-curl $ sudo apt-get install php7.2-bcmath # PHP Zip支持,提高网络以及内存压缩工具,提升性能 $ sudo apt-get install php-zip # PHP图像处理支持,imagick替代默认的GD图像处理,提升图像处理性能 $ sudo apt install php-imagick # 默认imagick是不启用的,需要手工开启 $ sudo phpenmod imagick $ sudo a2dismod mpm_prefork $ sudo a2enmod mpm_event $ sudo apt-get install libapache2-mod-fastcgi php7.2-fpm $ sudo service php7.2-fpm restart $ sudo a2enmod actions fastcgi alias proxy_fcgi $ sudo apt-get install php-mysql # 启用 Rewrite 模块,我们后续的WP Super Cache需要这个模块的支持 $ sudo a2enmod rewrite $ sudo service apache2 restart # 我们以root连接数据库,我们需要手工创建数据库,否则会出现如下错误: # “我们能够连接到数据库服务器(这意味着您的用户名和密码正确),但未能选择wordpress数据库。” $ mysql -u root -p -e "create database wordpress;" $ cd /var/www $ sudo chown -R www-data:www-data wordpress |
WordPress配置文件
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 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<VirtualHost *:80> # The ServerName directive sets the request scheme, hostname and port that # the server uses to identify itself. This is used when creating # redirection URLs. In the context of virtual hosts, the ServerName # specifies what hostname must appear in the request's Host: header to # match this virtual host. For the default virtual host (this file) this # value is not decisive as it is used as a last resort host regardless. # However, you must set it for any further virtual host explicitly. #ServerName www.example.com ServerAdmin webmaster@localhost #DocumentRoot /var/www/html DocumentRoot /var/www/wordpress <Directory /var/www/wordpress> #Options Indexes FollowSymLinks MultiViews Options FollowSymLinks MultiViews AllowOverride All # Apache 2.2 # FCGIWrapper /usr/bin/php5-cgi .php # AddHandler fcgid-script .php # Options ExecCGI SymLinksIfOwnerMatch # Apache 2.4.10 <FilesMatch \.php$> SetHandler "proxy:unix:/run/php/php7.2-fpm.sock|fcgi://localhost" </FilesMatch> Order allow,deny allow from all </Directory> # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, # error, crit, alert, emerg. # It is also possible to configure the loglevel for particular # modules, e.g. #LogLevel info ssl:warn ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # For most configuration files from conf-available/, which are # enabled or disabled at a global level, it is possible to # include a line for only one particular virtual host. For example the # following line enables the CGI configuration for this host only # after it has been globally disabled with "a2disconf". #Include conf-available/serve-cgi-bin.conf </VirtualHost> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet |
启用Apache2
的cache
,expire
,gzip
模块,加强服务器性能
1 2 3 4 5 6 7 |
$ sudo a2enmod cache $ sudo a2enmod expires $ sudo a2enmod deflate $ sudo service apache2 restart |
PHP-FPM进程数的设定,提高响应速度,解决页面加载时候缓慢的问题(如果感觉打开页面缓慢,建议调整下面的配置,这种情况尤其在访问量不大的时候会出现短暂的耗时增大,原因就是php进程被临时创建导致延迟增大)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 增大最大并发进程数量,默认为5 根据需要增大 $ sudo sed -i "s/^pm.max_children = 5/pm.max_children = 20/g" /etc/php/7.2/fpm/pool.d/www.conf # 增大系统启动初始化的进程数量,默认为 1 根据需要增大 $ sudo sed -i "s/^pm.start_servers = 1/pm.start_servers = 10/g" /etc/php/7.2/fpm/pool.d/www.conf # 增大保留的最低空闲进程数量,默认为 2 根据需要增大 $ sudo sed -i "s/^pm.min_spare_servers = 2/pm.min_spare_servers = 10/g" /etc/php/7.2/fpm/pool.d/www.conf # 增大保留的最高空闲进程数量,默认为 3 根据需要增大 $ sudo sed -i "s/^pm.max_spare_servers = 3/pm.max_spare_servers = 20/g" /etc/php/7.2/fpm/pool.d/www.conf # 配置进程在处理多少个请求之后就退出,避免某些操作导致内存泄漏,及时进行资源回收操作 $ sudo sed -i "s/^#pm.max_requests = 500/pm.max_requests = 5000/g" /etc/php/7.2/fpm/pool.d/www.conf |
启用PHP7的opcache配置
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 |
######避免PHP信息暴露在http头中 expose_php = Off ######在关闭display_errors后开启PHP错误日志(路径在php-fpm.conf中配置) log_errors = On ######开启opcache [opcache] ; Determines if Zend OPCache is enabled ;opcache.enable=0 opcache.enable=1 ; The OPcache shared memory storage size. ;opcache.memory_consumption=128 opcache.memory_consumption=256 ; The maximum number of keys (scripts) in the OPcache hash table. ; Only numbers between 200 and 1000000 are allowed. ;opcache.max_accelerated_files=10000 opcache.max_accelerated_files=1000000 ; When disabled, you must reset the OPcache manually or restart the ; webserver for changes to the filesystem to take effect. ;opcache.validate_timestamps=1 opcache.validate_timestamps=3000 |
重启服务
1 |
$ sudo service php7.2-fpm restart |
WP Statistics插件在开启缓存功能后无法统计访问量。
跟踪发现统计访问量使用的url返回401错误,如下:
1 2 3 |
https://www.mobibrw.com/wp-json/wpstatistics/v1/hit?_=1603432478&_wpnonce=1b5c35aa31&wp_statistics_hit_rest=yes&ua=Mozilla/5.0%20(Macintosh;%20Intel%20Mac%20OS%20X%2010_15_7)%20AppleWebKit/605.1.15%20(KHTML,%20like%20Gecko)%20Version/14.0%20Safari/605.1.15&url=https://www.mobibrw.com/2020/27156&referred= Failed to load resource: the server responded with a status of 401 (Unauthorized) |
比较奇怪的是,如果此时用户登陆,那么反倒不返回任何错误了。
最近在查看Limit Login Attempts
日志的时候,发现大量的登陆尝试,关键是登陆使用的用户名是正确的。感到很奇怪,用户名是如何泄漏的呢?
网上搜寻了一下,发现原来用户名是被WordPress
主动泄漏出来的。
WordPress
鼠标点击前台用户名,浏览器就会跳转到 https://www.mobibrw.com/author/username 这个链接,这样一来就直接暴露了登陆用户名,哪怕你已经在前台使用了昵称。这是个很大的安全隐患!
后台登陆用户名也可以这样查看到:https://www.mobibrw.com/?author=1,多用户的可以把 1 变为 2、3、4、5 等,就可以在地址栏查看到各个用户名。
为了避免暴露登陆用户名,我们需要配置禁止用户名显示。我们需要在当前使用的主题的functions.php
中增加如下函数
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
<?php /////////////////////隐藏用户名信息相关///////////////////// // 隐藏用户名 add_filter('author_link', function($link, $author_id, $author_nicename){ $author = get_userdata($author_id); if(sanitize_title($author->user_login) == $author_nicename){ global $wp_rewrite; $link = $wp_rewrite->get_author_permastruct(); $link = str_replace('%author%', $author_id, $link); $link = home_url(user_trailingslashit($link)); } return $link; }, 10, 3); // 原作者页直接404 add_action('pre_get_posts', function($wp_query) { if($wp_query->is_main_query() && $wp_query->is_author()) { if($author_name = $wp_query->get('author_name')){ $author_name = sanitize_title_for_query($author_name); $author = get_user_by('slug', $author_name); if($author) { if(sanitize_title($author->user_login) == $author->user_nicename){ $wp_query->set_404(); } } else { if(is_numeric($author_name)) { $wp_query->set('author_name', ''); $wp_query->set('author', $author_name); } } } } }); //修改body_class add_filter('body_class', function($classes) { if(is_author()) { global $wp_query; $author = $wp_query->get_queried_object(); if(sanitize_title($author->user_login) == $author->user_nicename) { $author_class = 'author-'.sanitize_html_class($author->user_nicename, $author->ID); $classes = array_diff($classes, [$author_class]); } } return $classes; }); //修改comment_class add_filter('comment_class', function ($classes) { foreach($classes as $key => $class) { if(strstr($class, 'comment-author-')) { unset($classes[$key]); } } return $classes; }); //禁用 REST API 过滤部分端点 //解决通过 https://www.mobibrw.com/wp-json/wp/v2/users 获取用户列表的问题 add_filter( 'rest_endpoints', function( $endpoints ){ if ( isset( $endpoints['/wp/v2/users'] ) ) { unset( $endpoints['/wp/v2/users'] ); } if ( isset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ) ) { unset( $endpoints['/wp/v2/users/(?P<id>[\d]+)'] ); } return $endpoints; }); // -- END ---------------------------------------- ?> |
自定义WordPress
插件的时候,需要判断当前用户的角色是不是网站管理员,如果是管理员的情况下才允许使用插件功能,否则禁止使用。
对于自定义主题的情况,可以使用如下代码:
1 2 3 4 5 6 7 8 9 |
function is_administrator() { // wp_get_current_user函数仅限在主题的functions.php中使用 $currentUser = wp_get_current_user(); if(!empty($currentUser->roles) && in_array('administrator', $currentUser->roles)) return True; // 是管理员 else return False; // 非管理员 } |
对于自定义插件的情况,可以使用如下代码:
1 2 3 4 5 6 7 8 9 |
function is_administrator() { if( is_user_logged_in() ) { //用户已登录,检查用户角色 global $current_user; if((!empty($current_user)) && (!empty($current_user->roles)) && in_array('administrator', $current_user->roles)) return True; // 是管理员 } return False; // 非管理员 } |
更简单的代码如下:
1 2 3 4 |
function is_administrator() { if( current_user_can( 'manage_options' ) ) { return True; } return False; // 非管理员 } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 目录相同链接位置 /usr/local/etc/apache22/conf/httpd22.conf $ sudo vim /volume1/@appstore/Apache2.2/usr/local/etc/apache22/conf/httpd22.conf # 重启 Apache2.2,有时候重启无效,此时请重启服务器 $ sudo /usr/syno/bin/synopkg restart httpd2.2 # 查看访问日志 $ sudo tail -f /var/log/httpd/apache22-access_log # 查看错误日志 $ sudo tail -f /var/log/httpd/apache22-error_log # DSM 7.x 查看错误日志 $ sudo tail -f /var/packages/Apache2.2/var/log/apache22-error_log |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
# 目录相同链接位置 /usr/local/etc/apache24/conf/httpd24.conf $ sudo vim /volume1/@appstore/Apache2.4/usr/local/etc/apache24/conf/httpd24.conf # 重启 Apache2.4,有时候重启无效,此时请重启服务器 $ sudo /usr/syno/bin/synopkg restart httpd2.4 # 查看访问日志 $ sudo tail -f /var/log/httpd/apache24-access_log # 查看错误日志 $ sudo tail -f /var/log/httpd/apache24-error_log # DSM 7.x 查看错误日志 $ sudo tail -f /var/packages/Apache2.4/var/log/apache24-error_log |
1 2 3 4 5 6 7 8 9 10 11 |
# nginx 配置文件 $ sudo vim /etc/nginx/nginx.conf # nginx 配置信息存储位置 $ sudo ls /usr/local/etc/nginx/conf.d # 重启nginx $ sudo synoservicecfg --restart nginx # 查看日志 $ sudo tail -f /var/log/nginx/error.log |
1 2 3 |
# 默认网页服务器根目录 /volume1/web |
有个简单需求,就是 WordPress
多个网站同步数据的情况下,根据网站域名的不同,修改数据库返回的数据。
实现这个的需求就是在当前 WordPress
主题下的 functions.php
中实现 the_post
拦截函数,在数据库返回的数之后,进行替换。
例子如下:
1 2 3 4 5 6 7 8 9 |
function replace_serv_domain($post) { $local_addr = $_SERVER['SERVER_ADDR']; if ('10.105.114.251' == $local_addr) { // 替换服务器的访问地址信息 $post->post_content = str_ireplace('mobibrw.com', 'miniab.com', $post->post_content); } return $post; } add_action('the_post', 'replace_serv_domain'); |
这个替换过程只能针对没有使用 WP Super Cache
进行缓存的情况,如果已经使用 WP Super Cache
进行缓存,那么很可能导致没有及时生效。
如果只是需要替换域名,那么只需要在 wp-config.php 中定义 WP_HOME/WP_SITEURL 两个变量即可实现域名覆盖。
示例参考代码如下:
1 2 3 4 5 6 7 8 9 10 |
$HTTP_TYPE = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://'; $HOME = $HTTP_TYPE.$_SERVER['HTTP_HOST'].'/wordpress'; #获取当前访问的域名 $SIT_URL = $HTTP_TYPE.$_SERVER['HTTP_HOST'].'/wordpress'; #$HOME = $HTTP_TYPE.$_SERVER['HTTP_HOST']; #$SIT_URL = $HTTP_TYPE.$_SERVER['HTTP_HOST']; define('WP_HOME', $HOME); define('WP_SITEURL', $SIT_URL); |
目前使用的阿里云服务器是通过参考 阿里云ECS ubuntu 14.04.5 LTS升级到ubuntu 16.04.2 LTS 升级上来的。
升级之后,默认情况下,依旧使用的是 ubuntu 16.04.5
自带的 PHP 7.0
,然而 ubuntu 18.04.3
系统自带的是 PHP 7.2
。我们希望在升级之后的系统上,能启用比较新版本的 PHP 7.2
。
其实更关键的是,在 ubuntu 18.04.3
系统上, PHP 7.0
相关的部分附加组件,比如 PHP7.0-CURL
已经没办法通过源安装了 ,安全补丁相关的更新估计也不能及时提供。另外就是较新版本的 PHP 7.2
在性能上有不错的提升。
执行如下切换命令(PHP-FPM
模式):
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 |
$ sudo apt-get install php7.2-fpm # 备份配置文件 $ sudo mv /etc/php/7.2/fpm/php.ini /etc/php/7.2/fpm/php.ini.bak # 拷贝配置文件 $ sudo cp /etc/php/7.0/fpm/php.ini /etc/php/7.2/fpm/php.ini $ sudo systemctl disable php7.0-fpm # 调整Apache与PHP-FPM通信的端口 $ sudo sed -i "s/php7.0-fpm.sock/php7.2-fpm.sock/g" /etc/apache2/sites-enabled/*.conf # 禁用旧服务 $ sudo service php7.0-fpm stop #重启服务 $ sudo service php7.2-fpm restart $ sudo service apache2 restart # 如果使用了WP-Statistics统计插件,需要安装依赖 $ sudo apt-get install php7.2-curl $ sudo apt-get install php7.2-bcmath |
网站响应速度有明显的提升,以前的卡顿表现明显改善。