linux - 基于 GeoIP 的 Apache 重写规则

标签 linux apache ubuntu reverse-proxy

目前,我正在尝试基于 GeoIP 重定向域。我已经安装了 GeoIP 模块。我有以下 domain.conf 文件。问题是登录工作正常,就像我的 example.com 将是印度用户的默认设置,而 us.example.com 将是美国用户访问该站点时的域。但目前得到

redirected you too many times. 
备注 :域正在按预期重定向,但出现上述错误。由于我的应用程序在 8080 端口上的 docker 中运行,因此我使用了反向代理。
如果有人能给出正确的 apache 重写规则,那就太好了。
<VirtualHost *:80>
      ServerName example.com
       ServerAlias example.com us.example.com
       ProxyRequests Off
      ProxyPreserveHost On
      ProxyPass / http://localhost:8080/
      ProxyPassReverse / http://localhost:8080/

      GeoIPEnable On
      GeoIPDBFile /usr/share/GeoIP/GeoIP.dat
      GeoIPScanProxyHeaders On


      RewriteEngine on
      RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^US$
      RewriteRule http://us.example.com$1


      LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined

      ErrorLog ${APACHE_LOG_DIR}/example.com-error_log
      CustomLog ${APACHE_LOG_DIR}/example.com-access_log common
</VirtualHost>
感谢提前

最佳答案

尝试:

RewriteEngine on
RewriteCond %{HTTP_HOST} !^us\.example\.com$ [NC]
RewriteCond "%{ENV:GEOIP_COUNTRY_CODE}" ^US$
RewriteRule ^ http://us.example.com [R=302,L]
您需要重新启动 apache,并确保在尝试查看上述是否有效之前清除浏览器缓存。
编辑:
OP 希望将所有非印度用户重定向到 example.co。
这是解决方案:
RewriteEngine On
RewriteCond %{HTTP_HOST} !(?:^|\.)example\.co$
RewriteCond %{ENV:GEOIP_COUNTRY_CODE} !^IN$
RewriteRule ^ http://example.co [R=302,L]

关于linux - 基于 GeoIP 的 Apache 重写规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70864239/

相关文章:

php - Zend : How to log PHP errors

apache - 如何覆盖/icons 的索引?

ubuntu - ubuntu 14.04 上 Neo4j 安装的主文件夹在哪里?

python - 加载python应用程序时Ubuntu服务器内存不足

php - Linux PHP Web 服务器 + Apache 或 Nginx

node.js - 尝试向 Google Cloud 上的 Ubuntu VM 发送 HTTP 请求

linux - scp上传文件需要执行权限吗?

linux - 迭代创建图形

Linux从零开始,Glibc-2.16 make报错

linux - stat命令如何计算文件的 block ?