httpd 发表于 2025-1-11 00:34:29

Apache配置CF顯示真實IP真難

不像Nginx直接引用外部IP列表文件就好了

httpd 发表于 2025-1-11 07:00:31

<div class="quote"><blockquote><font size="2"><a href="https://hostloc.com/forum.php?mod=redirect&goto=findpost&pid=16182678&ptid=1381865" target="_blank"><font color="#999999">abysscong 发表于 2025-1-11 01:50</font></a></font><br />
https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-v ...</blockquote></div><br />
IP列表文件是這樣的<br /><div class="blockcode"><div id="code_Mx1"><ol><li>root@3-us:/etc/apache2# cat conf-available/mod_remoteip.conf<br /><li>RemoteIPHeader X-Forwarded-For<br /><li>RemoteIPTrustedProxy 173.245.48.0/20<br /><li>RemoteIPTrustedProxy 103.21.244.0/22<br /><li>RemoteIPTrustedProxy 103.22.200.0/22<br /><li>RemoteIPTrustedProxy 103.31.4.0/22<br /><li>RemoteIPTrustedProxy 141.101.64.0/18<br /><li>RemoteIPTrustedProxy 108.162.192.0/18<br /><li>RemoteIPTrustedProxy 190.93.240.0/20<br /><li>RemoteIPTrustedProxy 188.114.96.0/20<br /><li>RemoteIPTrustedProxy 197.234.240.0/22<br /><li>RemoteIPTrustedProxy 198.41.128.0/17<br /><li>RemoteIPTrustedProxy 162.158.0.0/15<br /><li>RemoteIPTrustedProxy 104.16.0.0/13<br /><li>RemoteIPTrustedProxy 104.24.0.0/14<br /><li>RemoteIPTrustedProxy 172.64.0.0/13<br /><li>RemoteIPTrustedProxy 131.0.72.0/22<br /><li>RemoteIPTrustedProxy 2400:cb00::/32<br /><li>RemoteIPTrustedProxy 2606:4700::/32<br /><li>RemoteIPTrustedProxy 2803:f800::/32<br /><li>RemoteIPTrustedProxy 2405:b500::/32<br /><li>RemoteIPTrustedProxy 2405:8100::/32<br /><li>RemoteIPTrustedProxy 2a06:98c0::/29<br /><li>RemoteIPTrustedProxy 2c0f:f248::/32</ol></div><em onclick="copycode($('code_Mx1'));">复制代码</em></div>

abysscong 发表于 2025-1-11 01:50:00

https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/#apache-24

httpd 发表于 2025-1-11 01:50:17

<div class="quote"><blockquote><font size="2"><a href="https://hostloc.com/forum.php?mod=redirect&goto=findpost&pid=16182678&ptid=1381865" target="_blank"><font color="#999999">abysscong 发表于 2025-1-11 01:50</font></a></font><br />
https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-v ...</blockquote></div><div class="blockcode"><div id="code_tY2"><ol><li>root@3-us:~# cat /etc/apache2/apache2.conf<br /><li># This is the main Apache server configuration file.It contains the<br /><li># configuration directives that give the server its instructions.<br /><li># See http://httpd.apache.org/docs/2.4/ for detailed information about<br /><li># the directives and /usr/share/doc/apache2/README.Debian about Debian specific<br /><li># hints.<br /><li>#<br /><li>#<br /><li># Summary of how the Apache 2 configuration works in Debian:<br /><li># The Apache 2 web server configuration in Debian is quite different to<br /><li># upstream's suggested way to configure the web server. This is because Debian's<br /><li># default Apache2 installation attempts to make adding and removing modules,<br /><li># virtual hosts, and extra configuration directives as flexible as possible, in<br /><li># order to make automating the changes and administering the server as easy as<br /><li># possible.<br /><li><br /><li># It is split into several files forming the configuration hierarchy outlined<br /><li># below, all located in the /etc/apache2/ directory:<br /><li>#<br /><li>#   /etc/apache2/<br /><li>#   |-- apache2.conf<br /><li>#   |   `--ports.conf<br /><li>#   |-- mods-enabled<br /><li>#   |   |-- *.load<br /><li>#   |   `-- *.conf<br /><li>#   |-- conf-enabled<br /><li>#   |   `-- *.conf<br /><li>#   `-- sites-enabled<br /><li>#   `-- *.conf<br /><li>#<br /><li>#<br /><li># * apache2.conf is the main configuration file (this file). It puts the pieces<br /><li># together by including all remaining configuration files when starting up the<br /><li># web server.<br /><li>#<br /><li># * ports.conf is always included from the main configuration file. It is<br /><li># supposed to determine listening ports for incoming connections which can be<br /><li># customized anytime.<br /><li>#<br /><li># * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/<br /><li># directories contain particular configuration snippets which manage modules,<br /><li># global configuration fragments, or virtual host configurations,<br /><li># respectively.<br /><li>#<br /><li># They are activated by symlinking available configuration files from their<br /><li># respective *-available/ counterparts. These should be managed by using our<br /><li># helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See<br /><li># their respective man pages for detailed information.<br /><li>#<br /><li># * The binary is called apache2. Due to the use of environment variables, in<br /><li># the default configuration, apache2 needs to be started/stopped with<br /><li># /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not<br /><li># work with the default configuration.<br /><li><br /><li><br /><li># Global configuration<br /><li>#<br /><li><br /><li>#<br /><li># ServerRoot: The top of the directory tree under which the server's<br /><li># configuration, error, and log files are kept.<br /><li>#<br /><li># NOTE!If you intend to place this on an NFS (or otherwise network)<br /><li># mounted filesystem then please read the Mutex documentation (available<br /><li># at &lt;URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex&gt;);<br /><li># you will save yourself a lot of trouble.<br /><li>#<br /><li># Do NOT add a slash at the end of the directory path.<br /><li>#<br /><li>#ServerRoot &quot;/etc/apache2&quot;<br /><li><br /><li>#<br /><li># The accept serialization lock file MUST BE STORED ON A LOCAL DISK.<br /><li>#<br /><li>#Mutex file:${APACHE_LOCK_DIR} default<br /><li><br /><li>#<br /><li># The directory where shm and other runtime files will be stored.<br /><li>#<br /><li><br /><li>DefaultRuntimeDir ${APACHE_RUN_DIR}<br /><li><br /><li>#<br /><li># PidFile: The file in which the server should record its process<br /><li># identification number when it starts.<br /><li># This needs to be set in /etc/apache2/envvars<br /><li>#<br /><li>PidFile ${APACHE_PID_FILE}<br /><li><br /><li>#<br /><li># Timeout: The number of seconds before receives and sends time out.<br /><li>#<br /><li>Timeout 300<br /><li><br /><li>#<br /><li># KeepAlive: Whether or not to allow persistent connections (more than<br /><li># one request per connection). Set to &quot;Off&quot; to deactivate.<br /><li>#<br /><li>KeepAlive On<br /><li><br /><li>#<br /><li># MaxKeepAliveRequests: The maximum number of requests to allow<br /><li># during a persistent connection. Set to 0 to allow an unlimited amount.<br /><li># We recommend you leave this number high, for maximum performance.<br /><li>#<br /><li>MaxKeepAliveRequests 100<br /><li><br /><li>#<br /><li># KeepAliveTimeout: Number of seconds to wait for the next request from the<br /><li># same client on the same connection.<br /><li>#<br /><li>KeepAliveTimeout 5<br /><li><br /><li><br /><li># These need to be set in /etc/apache2/envvars<br /><li>User ${APACHE_RUN_USER}<br /><li>Group ${APACHE_RUN_GROUP}<br /><li><br /><li>#<br /><li># HostnameLookups: Log the names of clients or just their IP addresses<br /><li># e.g., www.apache.org (on) or 204.62.129.132 (off).<br /><li># The default is off because it'd be overall better for the net if people<br /><li># had to knowingly turn this feature on, since enabling it means that<br /><li># each client request will result in AT LEAST one lookup request to the<br /><li># nameserver.<br /><li>#<br /><li>HostnameLookups Off<br /><li><br /><li># ErrorLog: The location of the error log file.<br /><li># If you do not specify an ErrorLog directive within a &lt;VirtualHost&gt;<br /><li># container, error messages relating to that virtual host will be<br /><li># logged here.If you *do* define an error logfile for a &lt;VirtualHost&gt;<br /><li># container, that host's errors will be logged there and not here.<br /><li>#<br /><li>ErrorLog ${APACHE_LOG_DIR}/error.log<br /><li><br /><li>#<br /><li># LogLevel: Control the severity of messages logged to the error_log.<br /><li># Available values: trace8, ..., trace1, debug, info, notice, warn,<br /><li># error, crit, alert, emerg.<br /><li># It is also possible to configure the log level for particular modules, e.g.<br /><li># &quot;LogLevel info ssl:warn&quot;<br /><li>#<br /><li>LogLevel warn<br /><li><br /><li># Include module configuration:<br /><li>IncludeOptional mods-enabled/*.load<br /><li>IncludeOptional mods-enabled/*.conf<br /><li><br /><li># Include list of ports to listen on<br /><li>Include ports.conf<br /><li><br /><li><br /><li># Sets the default security model of the Apache2 HTTPD server. It does<br /><li># not allow access to the root filesystem outside of /usr/share and /var/www.<br /><li># The former is used by web applications packaged in Debian,<br /><li># the latter may be used for local directories served by the web server. If<br /><li># your system is serving content from a sub-directory in /srv you must allow<br /><li># access here, or in any related virtual host.<br /><li>&lt;Directory /&gt;<br /><li>Options FollowSymLinks<br /><li>AllowOverride None<br /><li>Require all denied<br /><li>&lt;/Directory&gt;<br /><li><br /><li>&lt;Directory /usr/share&gt;<br /><li>AllowOverride None<br /><li>Require all granted<br /><li>&lt;/Directory&gt;<br /><li><br /><li>&lt;Directory /var/www/&gt;<br /><li>Options Indexes FollowSymLinks<br /><li>AllowOverride None<br /><li>Require all granted<br /><li>&lt;/Directory&gt;<br /><li><br /><li>#&lt;Directory /srv/&gt;<br /><li>#   Options Indexes FollowSymLinks<br /><li>#   AllowOverride None<br /><li>#   Require all granted<br /><li>#&lt;/Directory&gt;<br /><li><br /><li><br /><li><br /><li><br /><li># AccessFileName: The name of the file to look for in each directory<br /><li># for additional configuration directives.See also the AllowOverride<br /><li># directive.<br /><li>#<br /><li>AccessFileName .htaccess<br /><li><br /><li>#<br /><li># The following lines prevent .htaccess and .htpasswd files from being<br /><li># viewed by Web clients.<br /><li>#<br /><li>&lt;FilesMatch &quot;^\.ht&quot;&gt;<br /><li>Require all denied<br /><li>&lt;/FilesMatch&gt;<br /><li><br /><li><br /><li>#<br /><li># The following directives define some format nicknames for use with<br /><li># a CustomLog directive.<br /><li>#<br /><li># These deviate from the Common Log Format definitions in that they use %O<br /><li># (the actual bytes sent including headers) instead of %b (the size of the<br /><li># requested file), because the latter makes it impossible to detect partial<br /><li># requests.<br /><li>#<br /><li># Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.<br /><li># Use mod_remoteip instead.<br /><li>#<br /><li>#LogFormat &quot;%v:%p %a %l %u %t &quot;%r&quot; %&gt;s %O &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;&quot; vhost_combined<br /><li>LogFormat &quot;%h %l %u %t &quot;%r&quot; %&gt;s %O &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;&quot; vhost_combined<br /><li>#LogFormat &quot;%a %l %u %t &quot;%r&quot; %&gt;s %O &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;&quot; combined<br /><li>LogFormat &quot;%a %l %u %t &quot;%r&quot; %&gt;s %O &quot;%{Referer}i&quot; &quot;%{User-Agent}i&quot;&quot; combined<br /><li>LogFormat &quot;%a %l %u %t &quot;%r&quot; %&gt;s %O&quot; common<br /><li>LogFormat &quot;%{Referer}i -&gt; %U&quot; referer<br /><li>LogFormat &quot;%{User-agent}i&quot; agent<br /><li>#设置访问日志的记录路径和格式<br /><li>CustomLog ${APACHE_LOG_DIR}/access.log combined<br /><li><br /><li># Include of directories ignores editors' and dpkg's backup files,<br /><li># see README.Debian for details.<br /><li><br /><li># Include generic snippets of statements<br /><li>IncludeOptional conf-enabled/*.conf<br /><li><br /><li># Include the virtual host configurations:<br /><li>IncludeOptional sites-enabled/*.conf<br /><li>GracefulShutDownTimeout 3<br /><li>AddOutputFilter INCLUDES .shtml<br /><li>AddType text/html .shtml<br /><li>AddType application/x-httpd-php .php<br /><li>AddType application/x-httpd-php-source .phps<br /><li><br /><li># 加載 mod_remoteip 模組<br /><li>LoadModule remoteip_module modules/mod_remoteip.so<br /><li><br /><li># 加載 CloudFlare IP列表文件<br /><li>Include conf-available/mod_remoteip.conf</ol></div><em onclick="copycode($('code_tY2'));">复制代码</em></div><br />
<br />
不知道這樣對不對
页: [1]
查看完整版本: Apache配置CF顯示真實IP真難