Welcome Guest, Not a member yet? Register   Sign In
Problems with Inferred base_url
#1

Hello, 

I'm building a re-usable app inside of a docker container. One of my requirements is that my static codebase can react to it's environment letting the server (nginx) in this case set up the $_SERVER environment so CI builds things correctly.

Specifically having trouble with base_url from the configs. If I leave the setting blank in the configs (as I can't hardcode one vs. another) it will pick up the internal docker container ip which is technically correct. However since these containers run behind a load balancer / proxy their actual front-facing url is different.

So I simply override SERVER_ADDR in the nginx.conf for the container and it should pass the correct endpoint along to the application, however I've ran into this sticky code:

https://github.com/bcit-ci/CodeIgniter/b...hp#L93-L96

It seems that if the SERVER_ADDR has a port specified CI is wrapping it in brackets.

What is the reason for this? Is there a different way for me to get CI to be told the server address it's running from? I'd really like to avoid having to gum up the source for each container that's built.
Reply
#2

$_SERVER['REMOTE_ADDR'] is an IP address, it doesn't and is not supposed to contain a port number.
A colon in it means an IPv6 address instead, which has to be put inside brackets when used in URLs.

You're not supposed to leave the 'base_url' empty!

This is described in:

- The stock application/config.php file
- The 2.2.x to 3.0.x upgrade instructions
- The 3.0.2 to 3.0.3 upgrade instructions

With that much effort on your part to somehow "cheat" the framework into using your environment variables for an empty base_url, you might as well just set the base_url based on your environment variables.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB