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

Apache反向代理子域名失效:访问子域名跳转主站问题排查

多站点部署问题:Apache反向代理子域名失效解决方案

问题根源

访问radarr.example.com跳转到主站,核心原因包括:Apache代理模块未启用、子域名虚拟主机配置不规范(如未使用ServerName、缺少HTTPS配置)、DNS解析错误或Apache站点优先级问题。


解决步骤

1. 启用Apache反向代理模块

首先确保Apache加载必需的代理模块:

sudo a2enmod proxy proxy_http
sudo systemctl restart apache2

2. 修正子域名虚拟主机配置

HTTP端口(80)配置:用于重定向到HTTPS

创建或修改/etc/apache2/sites-available/radarr.conf:

<VirtualHost *:80>
    ServerName radarr.example.com
    # 强制跳转到HTTPS
    Redirect permanent / https://radarr.example.com/
    ErrorLog /var/www/radarr/logs/error.log
    CustomLog /var/www/radarr/logs/access.log combined
</VirtualHost>

HTTPS端口(443)配置:反向代理核心

添加HTTPS配置(需先为子域名申请SSL证书):

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName radarr.example.com

    ProxyPreserveHost On
    ProxyRequests Off

    # 转发请求到局域网内的Radarr服务
    ProxyPass / http://192.168.1.20:7878/
    ProxyPassReverse / http://192.168.1.20:7878/

    ErrorLog /var/www/radarr/logs/error.log
    CustomLog /var/www/radarr/logs/access.log combined

    # 替换为子域名的SSL证书路径
    SSLCertificateFile /etc/letsencrypt/live/radarr.example.com/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/radarr.example.com/privkey.pem
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

Sonarr配置同理:复制上述文件,将radarr替换为sonarr,端口改为8989(Sonarr默认端口),并申请对应子域名的SSL证书。

3. 申请子域名SSL证书

使用certbot为子域名生成证书:

sudo certbot --apache -d radarr.example.com -d sonarr.example.com

该命令会自动配置HTTPS虚拟主机的证书部分,可省略手动编写证书路径的步骤。

4. 启用站点并验证配置

启用子域名站点:

sudo a2ensite radarr.conf sonarr.conf

检查Apache配置语法:

sudo apache2ctl configtest

若显示Syntax OK,重启Apache:

sudo systemctl restart apache2

5. 确认DNS解析

确保radarr.example.com和sonarr.example.com的A记录指向machine1的公网IP,这样外部请求才能到达反向代理服务器。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.07 19:05:21