WordPress
mysql -u root -pCREATE DATABASE wordpress;CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'strong_password_here';GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';FLUSH PRIVILEGES;EXIT;安装 WordPress
Section titled “安装 WordPress”使用 WP-CLI(推荐)
Section titled “使用 WP-CLI(推荐)”# 安装 WP-CLIcurl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.pharchmod +x wp-cli.pharmv wp-cli.phar /usr/local/bin/wp
# 下载 WordPresscd /var/www/example.comwp core download --allow-root
# 配置wp config create --allow-root \ --dbname=wordpress \ --dbuser=wpuser \ --dbpass=strong_password_here \ --dbhost=localhost
# 安装wp core install --allow-root \ --url=https://example.com \ --title="My Site" \ --admin_user=admin \ --admin_password=admin_password_here \
# 设置文件所有权chown -R nobody:nobody /var/www/example.comcd /var/www/example.comwget https://wordpress.org/latest.tar.gztar xzf latest.tar.gz --strip-components=1rm latest.tar.gzchown -R nobody:nobody .虚拟主机配置
Section titled “虚拟主机配置”virtualhost example { vhRoot /var/www/example.com configFile conf/vhosts/example/vhconf.conf allowSymbolLink 1 enableScript 1 restrained 1
docRoot $VH_ROOT/
index { indexFiles index.php, index.html }
scripthandler { add lsapi:lsphp php }
# 启用 .htaccess 处理 rewrite { enable 1 autoLoadHtaccess 1 }}WordPress 固定链接重写规则
Section titled “WordPress 固定链接重写规则”OLS 需要重写规则来支持 WordPress 的友好固定链接。有两种方式:
方式 A:OLS 原生重写(在 vhconf.conf 中)
Section titled “方式 A:OLS 原生重写(在 vhconf.conf 中)”rewrite { enable 1 autoLoadHtaccess 1
rules <<<END_rules RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] END_rules}方式 B:.htaccess(使用 LiteHTTPD 模块)
Section titled “方式 B:.htaccess(使用 LiteHTTPD 模块)”WordPress 会自动创建 .htaccess 文件。加载 LiteHTTPD 模块后,OLS 可以原生处理该文件:
# WordPress 默认 .htaccess<IfModule mod_rewrite.c>RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . /index.php [L]</IfModule>LiteSpeed Cache 插件
Section titled “LiteSpeed Cache 插件”LiteSpeed Cache 插件是在 OLS 上运行 WordPress 的核心优势。它提供服务器级全页面缓存,无需额外配置。
wp plugin install litespeed-cache --activate --allow-root或通过 WordPress 管理后台安装:插件 > 安装插件 > 搜索 “LiteSpeed Cache”。
启用 OLS 缓存模块
Section titled “启用 OLS 缓存模块”在 httpd_config.conf 中,确保缓存模块已加载:
module cache { ls_enabled 1
checkPublicCache 1 checkPrivateCache 1 maxCacheObjSize 10000000 maxStaleAge 200 qsCache 1 reqCookieCache 1 respCookieCache 1 ignoreReqCacheCtrl 1 ignoreRespCacheCtrl 0
storagePath /usr/local/lsws/cachedata}推荐插件设置
Section titled “推荐插件设置”激活后,进入 LiteSpeed Cache > 常规:
- 启用 LiteSpeed Cache:开启
- 访客模式:开启(为首次访问者提供缓存页面)
- 访客优化:开启
在 LiteSpeed Cache > 缓存 下:
- 缓存已登录用户:关闭(适用于大多数站点)
- 缓存评论者:关闭
- 缓存 REST API:开启
- 缓存移动端:开启(如果使用响应式主题,可与桌面端共用缓存)
# 通过 WP-CLI 清除所有缓存wp litespeed-purge all --allow-root
# 或通过 WordPress 后台管理栏清除WordPress 多站点
Section titled “WordPress 多站点”子目录多站点
Section titled “子目录多站点”默认的 .htaccess 重写规则适用于子目录多站点。WordPress 会生成:
RewriteEngine OnRewriteBase /RewriteRule ^index\.php$ - [L]
# 为 /wp-admin 添加尾部斜杠RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]RewriteCond %{REQUEST_FILENAME} -dRewriteRule ^ - [L]RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]RewriteRule . index.php [L]子域名多站点
Section titled “子域名多站点”对于子域名多站点,需要在 OLS 中配置通配符监听器,并在同一虚拟主机中使用通配符 ServerName:
listener Wildcard { address *:443 secure 1 map example *.example.com, example.com}禁止上传目录执行 PHP
Section titled “禁止上传目录执行 PHP”使用 LiteHTTPD 模块,在 wp-content/uploads/.htaccess 中添加:
<FilesMatch "\.php$"> Require all denied</FilesMatch>或通过 OLS 上下文在 vhconf.conf 中配置:
context /wp-content/uploads/ { allowBrowse 1 location $VH_ROOT/wp-content/uploads/
phpIniOverride { php_admin_flag engine off }}限制 wp-login.php 访问
Section titled “限制 wp-login.php 访问”使用 LiteHTTPD 模块在 .htaccess 中配置:
<Files wp-login.php> Require ip 192.168.1.0/24</Files>禁用 XML-RPC
Section titled “禁用 XML-RPC”<Files xmlrpc.php> Require all denied</Files>WordPress 推荐 php.ini 配置
Section titled “WordPress 推荐 php.ini 配置”memory_limit = 256Mupload_max_filesize = 64Mpost_max_size = 64Mmax_execution_time = 300max_input_vars = 5000
; OPcacheopcache.enable = 1opcache.memory_consumption = 256opcache.max_accelerated_files = 10000opcache.revalidate_freq = 60针对 WordPress 的 OLS 调优
Section titled “针对 WordPress 的 OLS 调优”extprocessor lsphp { type lsapi ... env PHP_LSAPI_CHILDREN=20 env LSAPI_MAX_REQS=5000 env PHP_LSAPI_MAX_IDLE=300 memSoftLimit 2047M memHardLimit 2047M}白屏(死亡白屏):
- 在
wp-config.php中启用 WP_DEBUG:define('WP_DEBUG', true); - 检查
/usr/local/lsws/logs/error.log
固定链接 404 错误:
- 确认虚拟主机中已启用
rewrite - 检查
autoLoadHtaccess是否为1,或重写规则是否已写入 vhconf.conf - 刷新重写规则:设置 > 固定链接 > 保存更改
LiteSpeed Cache 不生效:
- 确认
httpd_config.conf中已启用 OLS 缓存模块 - 检查
X-LiteSpeed-Cache响应头(应为hit或miss) - 确保
storagePath目录可写
- LiteSpeed Cache — 高级缓存配置
- 安全响应头 — 通过 OLS 或 .htaccess 添加安全响应头