跳转到内容

查看谁在访问你的站点:修订间差异

来自FC
FC留言 | 贡献
无编辑摘要
FC留言 | 贡献
无编辑摘要
 
第63行: 第63行:
'''如果在重启时报错 <code>Invalid command 'RemoteIPProxyProtocol'</code>:''' 这说明你的 Apache 版本太低,或者 <code>remoteip</code> 模块没加载成功。此时你可能需要升级 Apache,或者改用 Nginx 作为前置转发,因为 Nginx 对该协议的支持更早且更稳定。
'''如果在重启时报错 <code>Invalid command 'RemoteIPProxyProtocol'</code>:''' 这说明你的 Apache 版本太低,或者 <code>remoteip</code> 模块没加载成功。此时你可能需要升级 Apache,或者改用 Nginx 作为前置转发,因为 Nginx 对该协议的支持更早且更稳定。


使用过程中发现宿主机无法访问站点遂有接下来操作。
# 删除之前frpc.ini的配置即:<code>#proxy_protocol_version=v2</code>
# 重启frpc
# 开启apache的remoteip模块:<code>sudo a2enmod remoteip</code>
# 修改apache虚拟主机配置(在/etc/apache2/sites-enabled/config.conf)<syntaxhighlight>
<VirtualHost *:443>
    ServerName 你的域名
    # --- 核心配置开始 ---
    # 1. 确保关闭 Proxy Protocol (如果之前开了的话)
    RemoteIPProxyProtocol Off


使用过程中发现宿主机无法访问站点遂有接下来操作。
    # 2. 指定从 X-Forwarded-For 头部获取 IP
    RemoteIPHeader X-Forwarded-For
 
    # 3. 信任来自本地 frp 的代理请求
    RemoteIPInternalProxy 127.0.0.1
    # --- 核心配置结束 ---
 
    # ... 原有的 SSL 证书配置和 MediaWiki 目录配置保持不变 ...
    SSLEngine on
    SSLCertificateFile /path/to/cert
</VirtualHost>
</syntaxhighlight>
 
ok重启验证


* '''测试配置:''' <code>sudo apache2ctl configtest</code> (应显示 Syntax OK)
* '''重启:''' <code>sudo systemctl restart apache2</code>


[[分类:Apache]]
[[分类:Apache]]

2026年2月4日 (三) 22:35的最新版本

基于ubuntu22下apache2+frp,查看日志发现访问ip都是127.0.0.1,需要修改一下配置。

如果你是通过 HTTPS (443端口) 访问,且 SSL 证书是配置在 内网 Apache 服务器 上,情况会稍微复杂一点,因为 Apache 对 HTTPS 的 Proxy Protocol 支持主要依赖于 mod_remoteip 模块。

请按照以下步骤针对 HTTPS 进行配置:

1. 确认 frpc 配置

确保你的 frpc.ini 中,HTTPS 的代理部分开启了协议支持:

[web_https]
type = https  # 或者如果是 tcp 转发 443 
local_port = 443
custom_domains = your-wiki.com
proxy_protocol_version = v2

2. 配置 Apache 的 SSL 虚拟主机

你需要编辑处理 443 端口的配置文件(通常是 /etc/apache2/sites-enabled/default-ssl.conf 或类似的虚拟主机文件)。

<VirtualHost *:443> 块中加入以下指令:

Apache

<VirtualHost *:443>
    ServerName your-wiki.com

    # 1. 开启 Proxy Protocol 支持
    RemoteIPProxyProtocol On

    # 2. 声明信任来自本地 frp 转发的 IP
    RemoteIPInternalProxy 127.0.0.1

    # SSL 相关配置保持不变...
    SSLEngine on
    SSLCertificateFile /path/to/cert.pem
    SSLCertificateKeyFile /path/to/key.pem

    # 确保日志使用真实 IP
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

3. 修改全局日志格式 (非常重要)

如果这一步不做,日志里显示的依然会是 127.0.0.1。 编辑 /etc/apache2/apache2.conf,找到 LogFormat 定义行,将 %h 改为 %a

Apache

# 找到这一行(通常叫 combined)
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

# 修改为(将 %h 改为 %a):
LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined

4. 重启并验证

Bash

sudo a2enmod remoteip
sudo apache2ctl configtest
sudo systemctl restart apache2

⚠️ 特别提示:

  1. 版本要求RemoteIPProxyProtocol 指令需要 Apache 2.4.31 及以上版本。如果你的系统版本较老(如 Ubuntu 16.04 以前),可能不支持这个指令。
    • 查看版本命令:apache2 -v
  2. 连接断开问题:一旦你在 frpc 开启了 proxy_protocol_version = v2,Apache 的对应端口 必须 配置了 RemoteIPProxyProtocol On 才能正常通信。如果一处配了一处没配,会导致握手失败(SSL 错误或连接重置)。
  3. AWS 安全组:确保 AWS 服务端的 frp 监听端口(如 7000)和映射出的 443 端口都已经放行。

如果在重启时报错 Invalid command 'RemoteIPProxyProtocol' 这说明你的 Apache 版本太低,或者 remoteip 模块没加载成功。此时你可能需要升级 Apache,或者改用 Nginx 作为前置转发,因为 Nginx 对该协议的支持更早且更稳定。

使用过程中发现宿主机无法访问站点遂有接下来操作。

  1. 删除之前frpc.ini的配置即:#proxy_protocol_version=v2
  2. 重启frpc
  3. 开启apache的remoteip模块:sudo a2enmod remoteip
  4. 修改apache虚拟主机配置(在/etc/apache2/sites-enabled/config.conf)
    <VirtualHost *:443>
        ServerName 你的域名
    
        # --- 核心配置开始 ---
        # 1. 确保关闭 Proxy Protocol (如果之前开了的话)
        RemoteIPProxyProtocol Off
    
        # 2. 指定从 X-Forwarded-For 头部获取 IP
        RemoteIPHeader X-Forwarded-For
    
        # 3. 信任来自本地 frp 的代理请求
        RemoteIPInternalProxy 127.0.0.1
        # --- 核心配置结束 ---
    
        # ... 原有的 SSL 证书配置和 MediaWiki 目录配置保持不变 ...
        SSLEngine on
        SSLCertificateFile /path/to/cert
    </VirtualHost>

ok重启验证

  • 测试配置: sudo apache2ctl configtest (应显示 Syntax OK)
  • 重启: sudo systemctl restart apache2