OpenBSD 7.3环境下无法访问WordPress API及插件API问题求助
问题解决方案
一、处理WordPress对外请求失败问题
1. 检查OpenBSD PF防火墙规则
OpenBSD默认PF可能限制出站HTTP/HTTPS请求,先查看当前规则:
pfctl -sr
如果没有允许出站80/443端口的规则,编辑/etc/pf.conf添加:
pass out proto tcp from any to any port {80, 443}
重载PF规则:
pfctl -f /etc/pf.conf
2. 验证PHP cURL配置
WordPress依赖cURL发起外部请求,先确认cURL扩展已安装:
pkg_info | grep php-curl
若未安装,执行安装:
pkg_add php-curl
编辑PHP配置文件(路径通常为/etc/php-7.4.ini),确保以下配置正确:
allow_url_fopen = On curl.cainfo = "/etc/ssl/cert.pem" openssl.cafile = "/etc/ssl/cert.pem"
重启PHP-FPM服务:
rcctl restart php74_fpm
3. 修复wp-cron请求失败问题
- 先确认WordPress后台的
Site Address (URL)和WordPress Address (URL)已正确设置(后续改域名时同步处理)。 - 若本地回环请求被拦截,可在PF中允许本地流量:
pass inet proto tcp from 127.0.0.1 to 127.0.0.1 port 80 - 也可改用系统定时任务替代wp-cron:在
wp-config.php中添加:
然后添加系统cron任务(运行define('DISABLE_WP_CRON', true);crontab -e):*/5 * * * * php /path/to/your/wordpress/wp-cron.php > /dev/null 2>&1
二、处理站点URL从IP改域名报错问题
1. 强制设置WordPress站点URL
在wp-config.php中添加以下配置(替换为你的域名):
define('WP_HOME', 'https://yourdomain.com'); define('WP_SITEURL', 'https://yourdomain.com');
2. 替换数据库中旧IP记录
使用wp-cli(若已安装)执行:
wp search-replace 'http://139.180.143.200' 'https://yourdomain.com' --skip-columns=guid
若无wp-cli,直接在MariaDB中运行SQL命令:
USE your_wordpress_db; UPDATE wp_options SET option_value = REPLACE(option_value, 'http://139.180.143.200', 'https://yourdomain.com') WHERE option_name IN ('home', 'siteurl'); UPDATE wp_posts SET post_content = REPLACE(post_content, 'http://139.180.143.200', 'https://yourdomain.com'); UPDATE wp_postmeta SET meta_value = REPLACE(meta_value, 'http://139.180.143.200', 'https://yourdomain.com');
3. 验证Nginx配置
确保Nginx的server块中server_name正确指向你的域名,示例配置:
server { listen 80; listen [::]:80; server_name yourdomain.com www.yourdomain.com; root /path/to/wordpress; index index.php index.html; location / { try_files $uri $uri/ /index.php?$args; } location ~ \.php$ { fastcgi_pass unix:/var/run/php-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
重启Nginx服务:
rcctl restart nginx
4. 清理缓存
- 清理浏览器缓存并强制刷新页面(
Ctrl+F5) - 若使用缓存插件,在WordPress后台清理插件缓存
内容的提问来源于stack exchange,提问作者Lazuardi Insani
相关产品推荐
相关产品推荐

