0

I am having a problem serving my django project in a local network. Each project needs a unique domain name in the hosts file. In my local network other computers cannot see the projects.

my computer IP in the network is 192.168.2.2 The hosts file on my computer is like below:

127.0.0.101      myProject1.local
127.0.0.102      myProject2.local
127.0.0.103      myProject3.local

I think I have to make it like this, but it doesn't work.

192.168.2.101      myProject1.local
192.168.2.102      myProject2.local
192.168.2.103      myProject3.local
1

2 Answers 2

2

Finally, I found the solution. You must setup a DNS server in your local network, if you have any Server Edition OS computer it will be easy to config its DNS server and point it to your project's IP. but when there is no Server Computer in the network (eg: home networks) the problem will be finding a DNS server to curry the responsibility.

I will config Apache on Windows 7 or anything else to handling Django projects with WSGI...

my local IP is 192.168.2.2 and I Bind it with my MAC-ADDRESS in the Router Settings.
NOTICE: be sure to make your IP to be unchangeable, otherwise it will make your DNS Server and local Network unstable.

Config Apache to serve multiple Domains:

the first step is to config Apache to run the projects:
below will serve myProject1 on www.myproject1.local and myProject2 on www.myproject2.local

NameVirtualHost *:80

<VirtualHost *:80>
    ServerName www.myProject1.local
    ServerAlias myProject1.local *.myProject1.local 
    ServerAdmin [email protected]
    DocumentRoot "C:/path/to/myProject1/"
</VirtualHost>

<VirtualHost *:80>
    ServerName www.myProject2.local
    ServerAlias myProject2.local *.myProject2.local 
    ServerAdmin [email protected]
    DocumentRoot "C:/another/path/to/myProject2/"
</VirtualHost>

...

for more information visit : [Apache Name-based Virtual Host Support]

  1. Launch Django Projects with WSGI:

if you want to serve a PHP project its works, but to config WSGI you have to make a little changes like below. I treat project1 to be django project

<VirtualHost *:80>
    ServerName www.myProject1.local
    ServerAlias myProject1.local *.myProject1.local 
    ServerAdmin [email protected]
    #WSGIDaemonProcess myProject1 processes=2 threads=15 display-name=%{GROUP}
    #WSGIProcessGroup  myProject1
    WSGIScriptAlias / "C:/path/to/myProject1/myproject1.wsgi"
</VirtualHost>

...

Be sure to load : [mod_wsgi.so]

commented lines WSGIDaemonProcess and WSGIProcessGroup are options to perform better WSGI service for more informations visit : [mod_wsgi Wiki Pages]

  1. Installing a DNS Server

now you must config your dns server. in my case I have no dns server installed on my computer so first step is to find proper dns server to do the job.
I Use [MaraDNS], and config it like below:

mararc file

ipv4_bind_addresses             = "192.168.2.2"
timestamp_type                  = 2
random_seed_file                = "secret.txt"
hide_disclaimer                 = "YES"
csv2                            = {}
csv2["myproject1.local."]       = "db.default.txt"
csv2["myproject2.local."]       = "db.default.txt"
upstream_servers                = {}
upstream_servers["."]           = "yyy.yyy.yyy.yyy, zzz.zzz.zzz.zzz"

and the db.default.txt file like below

%           192.168.2.2 ~
www.%       192.168.2.2 ~

for more information about maraDNS visit MaraDNS Website

  1. Launching DNS Server:

Launch maraDNS Server by

maradns -f mararc
  1. Router Settings :

you could access your domains by setting primary DNS server to point to 192.168.2.2 for each computer in your local network. but you also could set the Router DHCP server to use your IP as the default DNS Server. it just need access to the Router web-Administration.
so enter your IP there as DNS Server and the job is done.

  1. Enjoy the Trick:

now you can to serve your projects in local network as faked domains without using :port-number or IP addresses. just enter myproject1.local in address-bar of any of your local network computer or WiFi devices and get the right result.
:)

2
0

What you are attempting to do is set multiple ip-addresses on the same host, not domain names. There are several problems with what you are trying to do: First you seem to set the hosts file only on the machine the server application is running on, which means that no other machine in the network will know about them.

Another problem is that to set multiple ip-addresses on the same host you have to do it in your network config, and how to do it differs depending on the operating system you are using.

The third thing is that you don't need one ip-address per host. One ip-address can have many hostnames. This is either set up in a name server, or if you don't have it for the local network, you can use aliases in the hosts file:

192.168.0.101   hostname1 hostname2 hostname3

Then in Apache (or whatever web-server you use) you use name-based virtual hosts.

And last a note about your current setup with using ip-addresses in the 127.x.x.x range, these are always considered local to the host, so trying to connect another computer through that address range will never work.

3
  • thanks for response, but i have to explicitly use fake domain names (eg: fakedomain.local) instead of IP addresses, so how can I setup my Win7 and ADSL-Router to get that result?
    – wtayyeb
    Nov 14, 2011 at 9:39
  • @wtayyeb Use the hosts-file, like in my example, and put the same line in all hosts files on all computers in the network. In my example, the same ip-address can be reached by using three different hostnames. Nov 14, 2011 at 9:45
  • but i still have problem with multiple django projects, there is only one port 80 for each IP so only one project at once can be lunched, and noo way remains just using :port_number after domain, and it is not good.
    – wtayyeb
    Nov 14, 2011 at 14:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .