You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

移除URL端口后WordPress站点无法访问(Ubuntu Server)

问题:WordPress站点无法通过不带端口的URL访问,带端口可正常访问

在Ubuntu Server环境下,WordPress站点通过带端口的URL(如www.pepitocorps.com:8091)可正常访问,但移除端口后的URL(如www.pepitocorps.com)无法打开。已排查过Vhost配置、WordPress后台站点URL设置、HAproxy负载均衡配置,也尝试通过wp-config.php及数据库修改站点URL,均未解决问题,需求是实现不带端口访问站点。

当前Vhost配置

<VirtualHost *:8090>
        ServerName pepitocorps.com
        ServerAlias www.pepitocorps.com
        DocumentRoot /var/www/html/wordpress2
        <Directory /var/www/html/wordpress2>
                Options +FollowSymlinks
                AllowOverride All
                Require all granted
        </Directory>
        ErrorLog /var/log/apache2/wp-error_log
        CustomLog /var/log/apache2/wp-access_log common
</VirtualHost>

当前HAproxy配置片段

frontend http_front
   bind *:80
   redirect scheme https code 301 if !{ ssl_fc }
   default_backend wordpress

frontend https
  bind *:443 ssl crt /etc/ssl/private/pepitocorps.com.pem

  acl wordpress_site hdr(host) -i www.pepitocorps.com
  use_backend wordpress if wordpress_site

  acl proxy hdr(host) -i ww2.pepitocorps.com
  use_backend proxy_html if proxy

  http-request set-header X-Forwarded-Proto https if { ssl_fc }
  http-request add-header SSL on if { ssl_fc }

  default_backend wordpress

backend wordpress
   balance roundrobin
   server server1 localhost:8091 check

backend proxy_html
   server server2 localhost:8090 check


frontend stats
  mode http
  bind *:8505
  stats enable
  stats uri /stats
  stats refresh 10

排查与解决步骤

1. 修正HAproxy后端与Apache监听端口的匹配问题

从配置看,HAproxy的wordpress后端指向localhost:8091,但Apache Vhost监听的是8090端口,这是核心不匹配点:

  • 修改Apache Vhost的监听端口为8091,与HAproxy后端一致:
    <VirtualHost *:8091>
            ServerName pepitocorps.com
            ServerAlias www.pepitocorps.com
            DocumentRoot /var/www/html/wordpress2
            <Directory /var/www/html/wordpress2>
                    Options +FollowSymlinks
                    AllowOverride All
                    Require all granted
            </Directory>
            ErrorLog /var/log/apache2/wp-error_log
            CustomLog /var/log/apache2/wp-access_log common
    </VirtualHost>
    
  • 重启Apache服务:sudo systemctl restart apache2

2. 验证HAproxy路由规则有效性

  • 访问HAproxy stats页面(http://你的服务器IP:8505/stats),查看www.pepitocorps.com的请求是否正确路由到wordpress后端
  • 确认域名www.pepitocorps.com已正确解析到服务器公网IP

3. 强制WordPress使用正确的外部访问URL

在wp-config.php中添加以下配置,确保站点识别不带端口的HTTPS地址:

define('WP_HOME', 'https://www.pepitocorps.com');
define('WP_SITEURL', 'https://www.pepitocorps.com');
define('FORCE_SSL_ADMIN', true);

若之前修改过数据库,检查wp_options表中的siteurl和home字段值是否为https://www.pepitocorps.com

4. 检查防火墙与服务状态

  • 允许80、443端口的入站流量:
    sudo ufw allow 80/tcp
    sudo ufw allow 443/tcp
    sudo ufw reload
    
  • 确认HAproxy服务正常运行:sudo systemctl status haproxy,异常则重启:sudo systemctl restart haproxy

5. 清除浏览器缓存

使用无痕模式访问站点,避免旧的跳转缓存干扰测试结果

内容的提问来源于stack exchange,提问作者Josh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 06:25:08