LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Testing web server on local network with ports... how to use with hosts file? (http://www.linuxquestions.org/questions/linux-server-73/testing-web-server-on-local-network-with-ports-how-to-use-with-hosts-file-731462/)

raisinlove 06-08-2009 01:45 PM

Testing web server on local network with ports... how to use with hosts file?
 
Hey all,
I have just setup a local webserver on a (virtual machine) Ubuntu box.
I have successfully set up multiple sites via virtual hosting using the server's IP with a different port number for each website.

Since this is only intended for local testing, it wasn't necessairy to access these via the web, so I went ahead and added each adress to my local Windows HOSTS file so I could test the websites with their actual domain names.

I found out you can't use port numbers in the HOSTS file... So what are the alternatives?

acid_kewpie 06-08-2009 01:50 PM

using different port numbers totally undermines the point of virtual hosts. the whole point that virtual hosts exist is to be able to serve multiple sites on ONE port, i.e port 80 (and 443). Reconfigure your apache config to not use multiple ports.

And please don't think that not being able to use port numbers in your host file is a short coming of anything at all. It makes no sense at all to associate a domain name with a port, just totally illogical.

secesh 06-08-2009 01:50 PM

you don't need to assign a different port to discriminate virtual hosts -- they can all be listening on port 80.

But put the domains in your hosts file pointing to the ubuntu box's IP. Then from your browser (on the machine with the modified hosts file) try to browse to the domain.

if it doesn't pull up, flush your cache and try again. also: ping the domain to verify your hosts file is correct.

pliqui 06-08-2009 02:24 PM

Indeed, like secesh and acid_kewpie said, you don't need to configure every site with a different port, i will paste my httpd.conf and see that all the sites have the same port.

Code:

NameVirtualHost *:80

<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName desabancodevenezuela.com
        ServerAlias www.desabancodevenezuela.com

        # Indexes + Directory Root.
        DirectoryIndex index.php
        DocumentRoot /var/www/desabancodevenezuela.com

        # Logfiles
        ErrorLog  /var/www/desabancodevenezuela.com/logs/error.log
        CustomLog /var/www/desabancodevenezuela.com/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName munin
        ServerAlias munin

        # Indexes + Directory Root.
        DirectoryIndex index.html
        DocumentRoot /var/www/munin

        # Logfiles
        ErrorLog  /var/www/munin/logs/error.log
        CustomLog /var/www/munin/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName sep
        ServerAlias sep

        # Indexes + Directory Root.
        DirectoryIndex index.php
        DocumentRoot /var/www/sep

        # Logfiles
        ErrorLog  /var/www/munin/logs/error.log
        CustomLog /var/www/munin/logs/access.log combined
</VirtualHost>

<VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName webalizer
        ServerAlias webalizer

        # Indexes + Directory Root.
        DirectoryIndex index.html
        DocumentRoot /var/www/webalizer

        # Logfiles
        ErrorLog  /var/www/webalizer/logs/error.log
        CustomLog /var/www/webalizer/logs/access.log combined
</VirtualHost>

And you can see on my windows machine i just configure the host to same ip

Code:

120.48.28.32    desabancodevenezuela
120.48.28.32    munin
120.48.28.32    cacti
120.48.28.32    sep
120.48.28.32    webalizer


raisinlove 06-08-2009 02:39 PM

Thanks guys,
the logic behind my use of ports was simply that I had tried doing this way before and it had failed. Finding that it worked with the ports led me to believe that I fixed my problem this way, when it was actually something unrelated that caused my previous config not to recognized multiple websites. In short, I went back to the basic way as suggested above and it works great.

Quote:

Originally Posted by acid_kewpie (Post 3567048)
And please don't think that not being able to use port numbers in your host file is a short coming of anything at all. It makes no sense at all to associate a domain name with a port, just totally illogical.

Nah, I just thought it would be ok since I'm only accessing the sites localy. But I realize now it was overkill.


All times are GMT -5. The time now is 06:37 PM.