Config uses local ip address behind NAT so I cant access from WWW

Config uses local ip address behind NAT so I cant access from WWW

by Wayne Hamilton -
Number of replies: 7
When I installed/configured moodle the local ip address has been used which is behind NAT. So all works fine when I'm on my local network at home but I cant access it from the WWW.

I dont think its a problem with my NAT or DNS etc as I can access a test.php from the WWW

I noticed that in config.php I have the line
$CFG->wwwroot = 'http://192.168.1.254/moodle';

I'm guessing I need to change this to something like
$CFG->wwwroot = 'http://my.domian.com/moodle';

However just editing this on its own this doesn't fix things, I'm guessing I need to rerun some script to action it?

Any help appreciated
Wayne
Average of ratings: -
In reply to Wayne Hamilton

Re: This is what I did.

by Mark Wong -
You will have to modify it for your use..

I made it accesable iinside the FW and outside.

Comment out $CFG->wwwroot = 'http://192.168.1.254/moodle';

Add:
if($ipstr == '10.')
{
$CFG->wwwroot = 'http://10.1.1.75/moodle;
}
else
{
$CFG->wwwroot = 'http://[firewall IP address]/moodle';
}

Simple and works well!
In reply to Mark Wong

Re: This is what I did.

by Mark Wong -
BTW, 10.1.1 is my NAT network, yours is 192.168.1, but I'm sure you already know that.  Just want to be clear..
In reply to Mark Wong

Re: This is what I did.

by Mark Wong -
Ok.. let me fix this one more time. It seemed to work from 1.4, but not on 1.5, though I don't know if that really was the problem.  If you do this... it will work...

$ipstr = getenv('REMOTE_ADDR');
$ips = substr($ipstr, 0, 3);
if (ips == '10.')
{
$CFG->wwwroot = 'http://[trusted IP]/moodle';
}
else
{
$CFG->wwwroot = 'http://[firewall IP]/moodle';
}

This really works...
In reply to Mark Wong

Re: This is what I did.

by Jean Meadows -

Hi Mark,

I did it and it still didn't work....

Any other ideas...

Jeannie

In reply to Mark Wong

Re: This is what I did.

by Carlos Correa -

I tried and didn´t work sad


Do you´ll know other news tips???


Regards.

In reply to Carlos Correa

Re: This is what I did.

by Emma Richardson -
Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Plugin developers

You need to set up a domain name that is mapped to from outside (www) and internal network with DNS.  Then in config.php change $CFG->wwwroot = 'http://192.168.1.254/moodle' to $CFG->wwwroot='http://yourdomainname.com/moodle.  

After doing this, you need to restart apache.  Then you will need to run replace.php on your database to update all the references there.

On a side note, to make this work best, you should direct apache to your moodle folder by default, then you will not need the /moodle at the end of your domain name.  

In reply to Emma Richardson

Re: This is what I did.

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

^^ This.

This sort of thing isn't ideal either way (use proper hosting, or find a server with a 'real' IP address) but it's preferable to use a split DNS over the config.php 'fiddle'.

Both have slight security issues unfortunately.