让 codeigniter 以正确的方式猜测 $baseurl

make codeigniter guess $baseurl the correct way

在我的服务器上,我在端口 8081 上使用 nginx,在端口 80 上使用 apache 作为 nginx 的内部代理。

而且我有多个域 .org,.com,.net

当我在配置代码中将 $base_url 留空时,点火器尝试猜测正确的基数 url ,它表明基数 url 是 localhost:8081 而不是domain.orgdomain.com

当我手动设置时:

$base_url="domain.com";

当我打开 domain.org 等其他域时它不起作用,因为 $base_url 仍在 .com 域中。

有什么方法可以让 code igniter 更聪明地猜对 $base_url 吗?

感谢夏洛特的提示。

在搜索 HTTP_HOST 服务器变量后,我发现 apache 正在将 HTTP_HOST 作为 localhost:8081.

传递给 nginx

我在 apache 中使用反向代理来制作代理行为:

ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/

我搜索了 apache 的 Documentation 并找到了一个名为 ProxyPreserveHost

的指令

When enabled, this option will pass the Host: line from the incoming request to the proxied host, instead of the hostname specified in the ProxyPass line.

我通过添加这一行来启用它:

ProxyPreserveHost On

它起作用了,现在 codeigniter 可以正确读取 HTTP_HOST 并使 $base_url 正确。

config.php 中设置 base_url。
像这样
$config['base_url'] = 'actual url'

$config['base_url'] = 'http://'. $_SERVER['HTTP_HOST'].'/';