全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 178|回复: 3

Apache配置CF顯示真實IP真難

[复制链接]
发表于 5 天前 | 显示全部楼层 |阅读模式
不像Nginx直接引用外部IP列表文件就好了
 楼主| 发表于 5 天前 | 显示全部楼层
abysscong 发表于 2025-1-11 01:50
https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-v ...

IP列表文件是這樣的
  1. root@3-us:/etc/apache2# cat conf-available/mod_remoteip.conf
  2. RemoteIPHeader X-Forwarded-For
  3. RemoteIPTrustedProxy 173.245.48.0/20
  4. RemoteIPTrustedProxy 103.21.244.0/22
  5. RemoteIPTrustedProxy 103.22.200.0/22
  6. RemoteIPTrustedProxy 103.31.4.0/22
  7. RemoteIPTrustedProxy 141.101.64.0/18
  8. RemoteIPTrustedProxy 108.162.192.0/18
  9. RemoteIPTrustedProxy 190.93.240.0/20
  10. RemoteIPTrustedProxy 188.114.96.0/20
  11. RemoteIPTrustedProxy 197.234.240.0/22
  12. RemoteIPTrustedProxy 198.41.128.0/17
  13. RemoteIPTrustedProxy 162.158.0.0/15
  14. RemoteIPTrustedProxy 104.16.0.0/13
  15. RemoteIPTrustedProxy 104.24.0.0/14
  16. RemoteIPTrustedProxy 172.64.0.0/13
  17. RemoteIPTrustedProxy 131.0.72.0/22
  18. RemoteIPTrustedProxy 2400:cb00::/32
  19. RemoteIPTrustedProxy 2606:4700::/32
  20. RemoteIPTrustedProxy 2803:f800::/32
  21. RemoteIPTrustedProxy 2405:b500::/32
  22. RemoteIPTrustedProxy 2405:8100::/32
  23. RemoteIPTrustedProxy 2a06:98c0::/29
  24. RemoteIPTrustedProxy 2c0f:f248::/32
复制代码
发表于 5 天前 | 显示全部楼层
https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-visitor-ips/#apache-24
 楼主| 发表于 5 天前 | 显示全部楼层
abysscong 发表于 2025-1-11 01:50
https://developers.cloudflare.com/support/troubleshooting/restoring-visitor-ips/restoring-original-v ...
  1. root@3-us:~# cat /etc/apache2/apache2.conf
  2. # This is the main Apache server configuration file.  It contains the
  3. # configuration directives that give the server its instructions.
  4. # See http://httpd.apache.org/docs/2.4/ for detailed information about
  5. # the directives and /usr/share/doc/apache2/README.Debian about Debian specific
  6. # hints.
  7. #
  8. #
  9. # Summary of how the Apache 2 configuration works in Debian:
  10. # The Apache 2 web server configuration in Debian is quite different to
  11. # upstream's suggested way to configure the web server. This is because Debian's
  12. # default Apache2 installation attempts to make adding and removing modules,
  13. # virtual hosts, and extra configuration directives as flexible as possible, in
  14. # order to make automating the changes and administering the server as easy as
  15. # possible.

  16. # It is split into several files forming the configuration hierarchy outlined
  17. # below, all located in the /etc/apache2/ directory:
  18. #
  19. #       /etc/apache2/
  20. #       |-- apache2.conf
  21. #       |       `--  ports.conf
  22. #       |-- mods-enabled
  23. #       |       |-- *.load
  24. #       |       `-- *.conf
  25. #       |-- conf-enabled
  26. #       |       `-- *.conf
  27. #       `-- sites-enabled
  28. #               `-- *.conf
  29. #
  30. #
  31. # * apache2.conf is the main configuration file (this file). It puts the pieces
  32. #   together by including all remaining configuration files when starting up the
  33. #   web server.
  34. #
  35. # * ports.conf is always included from the main configuration file. It is
  36. #   supposed to determine listening ports for incoming connections which can be
  37. #   customized anytime.
  38. #
  39. # * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
  40. #   directories contain particular configuration snippets which manage modules,
  41. #   global configuration fragments, or virtual host configurations,
  42. #   respectively.
  43. #
  44. #   They are activated by symlinking available configuration files from their
  45. #   respective *-available/ counterparts. These should be managed by using our
  46. #   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
  47. #   their respective man pages for detailed information.
  48. #
  49. # * The binary is called apache2. Due to the use of environment variables, in
  50. #   the default configuration, apache2 needs to be started/stopped with
  51. #   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
  52. #   work with the default configuration.


  53. # Global configuration
  54. #

  55. #
  56. # ServerRoot: The top of the directory tree under which the server's
  57. # configuration, error, and log files are kept.
  58. #
  59. # NOTE!  If you intend to place this on an NFS (or otherwise network)
  60. # mounted filesystem then please read the Mutex documentation (available
  61. # at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
  62. # you will save yourself a lot of trouble.
  63. #
  64. # Do NOT add a slash at the end of the directory path.
  65. #
  66. #ServerRoot "/etc/apache2"

  67. #
  68. # The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
  69. #
  70. #Mutex file:${APACHE_LOCK_DIR} default

  71. #
  72. # The directory where shm and other runtime files will be stored.
  73. #

  74. DefaultRuntimeDir ${APACHE_RUN_DIR}

  75. #
  76. # PidFile: The file in which the server should record its process
  77. # identification number when it starts.
  78. # This needs to be set in /etc/apache2/envvars
  79. #
  80. PidFile ${APACHE_PID_FILE}

  81. #
  82. # Timeout: The number of seconds before receives and sends time out.
  83. #
  84. Timeout 300

  85. #
  86. # KeepAlive: Whether or not to allow persistent connections (more than
  87. # one request per connection). Set to "Off" to deactivate.
  88. #
  89. KeepAlive On

  90. #
  91. # MaxKeepAliveRequests: The maximum number of requests to allow
  92. # during a persistent connection. Set to 0 to allow an unlimited amount.
  93. # We recommend you leave this number high, for maximum performance.
  94. #
  95. MaxKeepAliveRequests 100

  96. #
  97. # KeepAliveTimeout: Number of seconds to wait for the next request from the
  98. # same client on the same connection.
  99. #
  100. KeepAliveTimeout 5


  101. # These need to be set in /etc/apache2/envvars
  102. User ${APACHE_RUN_USER}
  103. Group ${APACHE_RUN_GROUP}

  104. #
  105. # HostnameLookups: Log the names of clients or just their IP addresses
  106. # e.g., www.apache.org (on) or 204.62.129.132 (off).
  107. # The default is off because it'd be overall better for the net if people
  108. # had to knowingly turn this feature on, since enabling it means that
  109. # each client request will result in AT LEAST one lookup request to the
  110. # nameserver.
  111. #
  112. HostnameLookups Off

  113. # ErrorLog: The location of the error log file.
  114. # If you do not specify an ErrorLog directive within a <VirtualHost>
  115. # container, error messages relating to that virtual host will be
  116. # logged here.  If you *do* define an error logfile for a <VirtualHost>
  117. # container, that host's errors will be logged there and not here.
  118. #
  119. ErrorLog ${APACHE_LOG_DIR}/error.log

  120. #
  121. # LogLevel: Control the severity of messages logged to the error_log.
  122. # Available values: trace8, ..., trace1, debug, info, notice, warn,
  123. # error, crit, alert, emerg.
  124. # It is also possible to configure the log level for particular modules, e.g.
  125. # "LogLevel info ssl:warn"
  126. #
  127. LogLevel warn

  128. # Include module configuration:
  129. IncludeOptional mods-enabled/*.load
  130. IncludeOptional mods-enabled/*.conf

  131. # Include list of ports to listen on
  132. Include ports.conf


  133. # Sets the default security model of the Apache2 HTTPD server. It does
  134. # not allow access to the root filesystem outside of /usr/share and /var/www.
  135. # The former is used by web applications packaged in Debian,
  136. # the latter may be used for local directories served by the web server. If
  137. # your system is serving content from a sub-directory in /srv you must allow
  138. # access here, or in any related virtual host.
  139. <Directory />
  140.         Options FollowSymLinks
  141.         AllowOverride None
  142.         Require all denied
  143. </Directory>

  144. <Directory /usr/share>
  145.         AllowOverride None
  146.         Require all granted
  147. </Directory>

  148. <Directory /var/www/>
  149.         Options Indexes FollowSymLinks
  150.         AllowOverride None
  151.         Require all granted
  152. </Directory>

  153. #<Directory /srv/>
  154. #       Options Indexes FollowSymLinks
  155. #       AllowOverride None
  156. #       Require all granted
  157. #</Directory>




  158. # AccessFileName: The name of the file to look for in each directory
  159. # for additional configuration directives.  See also the AllowOverride
  160. # directive.
  161. #
  162. AccessFileName .htaccess

  163. #
  164. # The following lines prevent .htaccess and .htpasswd files from being
  165. # viewed by Web clients.
  166. #
  167. <FilesMatch "^\.ht">
  168.         Require all denied
  169. </FilesMatch>


  170. #
  171. # The following directives define some format nicknames for use with
  172. # a CustomLog directive.
  173. #
  174. # These deviate from the Common Log Format definitions in that they use %O
  175. # (the actual bytes sent including headers) instead of %b (the size of the
  176. # requested file), because the latter makes it impossible to detect partial
  177. # requests.
  178. #
  179. # Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
  180. # Use mod_remoteip instead.
  181. #
  182. #LogFormat "%v:%p %a %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
  183. LogFormat "%h %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" vhost_combined
  184. #LogFormat "%a %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined
  185. LogFormat "%a %l %u %t "%r" %>s %O "%{Referer}i" "%{User-Agent}i"" combined
  186. LogFormat "%a %l %u %t "%r" %>s %O" common
  187. LogFormat "%{Referer}i -> %U" referer
  188. LogFormat "%{User-agent}i" agent
  189. #设置访问日志的记录路径和格式
  190. CustomLog ${APACHE_LOG_DIR}/access.log combined

  191. # Include of directories ignores editors' and dpkg's backup files,
  192. # see README.Debian for details.

  193. # Include generic snippets of statements
  194. IncludeOptional conf-enabled/*.conf

  195. # Include the virtual host configurations:
  196. IncludeOptional sites-enabled/*.conf
  197. GracefulShutDownTimeout 3
  198. AddOutputFilter INCLUDES .shtml
  199. AddType text/html .shtml
  200. AddType application/x-httpd-php .php
  201. AddType application/x-httpd-php-source .phps

  202. # 加載 mod_remoteip 模組
  203. LoadModule remoteip_module modules/mod_remoteip.so

  204. # 加載 CloudFlare IP列表文件
  205. Include conf-available/mod_remoteip.conf
复制代码


不知道這樣對不對
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-1-16 12:28 , Processed in 0.064891 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表