Welcome Guest, Not a member yet? Register   Sign In
Make CodeIgniter work behind apache with nginx as intermediary
#1

Hi
I've installed latest Apache, PHP7 and codeigniter in a Ubuntu 17.04 server, which has a static IP (eg: 10.20.30.40)
I'm on a big corporative LAN and now this codeigniter app needs to be accessed from outside (internet)

Tere's an intermediary nginx server (which I cannot access) that redirects everything from outside (internet) to my server
So:
http://www.subdomain.company.xxx/ci/index.php/test
should load exactly the same as
http://10.20.30.40/ci/index.php/test

But only the local url works fine
When I call from outside (or using anon proxy from internet) I get the codeigniter 404 page (not even the custom 404 apache errorpage I've set)

There's no .htaccess nor config change made. It is just a base codeigniter install for testing this

Any ideas?

Thanks a lot in advance,
Reply
#2

(This post was last modified: 08-02-2017, 05:28 PM by natanfelles. Edit Reason: ;) )

If you can see the CodeIgniter 404 it looks that you need configure your Base URL.

PHP Code:
$config['base_url'] = $_SERVER['HTTP_HOST'] == '10.20.30.40' 'http://10.20.30.40/ci/' 'http://www.subdomain.company.xxx/ci/'
Reply
#3

Hi @natanfelles
Thanks for the reply. I've changed base_url config to that but the behaviour is the same.

Now, one thing I've noticed debugging variables with xdebug

1. When I call http://10.20.30.40/ci/ this variable gets the following value and page works fine
$_SERVER['REQUEST_URI'] = string '/ci/' (length=5)

2. When I call http://subdomain.company.xxx/ci/ the same variable gets the following value and page throws CI's 404
$_SERVER['REQUEST_URI'] = string '//ci/' (length=5)
(note //ci/ with double bar)

3. If I load http://10.20.30.40//ci/ (note double bar) I get CI's 404

Maybe something related to $_SERVER['REQUEST_URI'] ?

Lemme know if you would need all the debugged variables

Thanks
Reply
#4

Finally solved by setting uri_protocol = PATH_INFO

application/config/config.php

PHP Code:
$config['base_url'] = $_SERVER['HTTP_HOST'] == '10.20.30.40' 'http://10.20.30.40/ci/' 'http://www.subdomain.company.xxx/ci/'
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO'

and .htaccess like

Code:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Now it is working perfect locally and loaded from Internet
Reply




Theme © iAndrew 2016 - Forum software by © MyBB