dp518158
dp518158
2016-08-11 10:23
浏览 44
已采纳

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

On my server i'm using nginx on port 8081 and apache on port 80 as an internal proxy to nginx.

And i have multiple domains .org,.com,.net

When i leave the $base_url empty in the config code igniter tries to guess the right base url , it shows that the base url is localhost:8081 instead of domain.org or domain.com

When i set it manually:

$base_url="domain.com";

It doesn't work when i open the other domains like domain.org for example because the $base_url is still on the .com domain .

Is there any way to make code igniter smarter guessing the right $base_url ?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanpanzhu2910
    duanpanzhu2910 2016-08-11 12:25
    已采纳

    Thanks Charlotte for the tip.

    After some search on the HTTP_HOST server variable i discovered that apache is passing the HTTP_HOST to nginx as localhost:8081.

    I use reverse proxy in apache to make the proxy behavior:

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

    I searched the Documentation of apache and found a directive called 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.

    i enabled it by adding this line:

    ProxyPreserveHost On

    And it worked , now codeigniter can read HTTP_HOST right and make the $base_url right.

    点赞 评论
  • dongmaomou4117
    dongmaomou4117 2016-08-16 06:45

    sett base_url in config.php .
    like this
    $config['base_url'] = 'actual url'
    or
    $config['base_url'] = 'http://'. $_SERVER['HTTP_HOST'].'/';

    点赞 评论

相关推荐