Virtual Hosting, quick and simple
Forum » Forum / Installing & Configuring Programs » Virtual Hosting, quick and simple
Started by: fraterfrater
On: 1213839583|%e %b %Y, %H:%M %Z|agohover
Number of posts: 9
rss icon RSS: New posts
Virtual Hosting, quick and simple
fraterfrater 1213839583|%e %b %Y, %H:%M %Z|agohover

I have a Linux server with Apache and virtual hosting installed and like to keep things as simple as possible.
I'm using the normal directory structure as the database for all the virtual hosts.
Creating a new virtual host is as simple as creating a directory in the right place.
I have it working on my Fedora Core machine with Apache, but also wanted to have it on my WDMB.

Every week a cronjob is pulling my complete vhost folder from my Linux machine to the worldbook and I thought it was a good idea to be able to use it in the same way.
For now I'm running vhosting on port 8080, but that's more an enhancement.
It's even easier to let it run everything on port 80

ok… let's start

I don't like to change configs that are already there, so I'm keeping that to the minimum.
I will create a special directory for the new configs…

mkdir /etc/lighttpd/conf.d

Add a line to /etc/lighttpd/lighttpd.conf, but first backup your conf

cp -p /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.`date +%F`
echo -e "include_shell \"cat /etc/lighttpd/conf.d/*.conf\"" >> /etc/lighttpd/lighttpd.conf
vi /etc/lighttpd/conf.d/evhost.conf

Create the file /etc/lighttpd/conf.d/evhost.conf with the following content
server.modules += ( "mod_evhost" )

$SERVER["socket"] == ":8080" {
        server.document-root = "/shares/internal/WWW/vhosts/oops/"
        evhost.path-pattern        = "/shares/internal/WWW/vhosts/%1/%2/%3/"
                }
mkdir -p /shares/internal/WWW/vhosts
chown -R www-data:www-data /shares/internal/WWW

/etc/init.d/lighttpd.sh restart

Your directory structure can look like this:

/shares/internal/WWW/vhosts/oops
/shares/internal/WWW/vhosts/com/wikidot/myworldbook
/shares/internal/WWW/vhosts/com/wikidot/www
/shares/internal/WWW/vhosts/com/wikidot/hacking
/shares/internal/WWW/vhosts/com/mybook/www
/shares/internal/WWW/vhosts/net/martinhinner/www
/shares/internal/WWW/vhosts/org/hacking/www

That's it really….

After understanding the concept you can "upgrade" the setup by running the non-vhost on port 8080 and make the vhosting on port 80.

Your normal admin-page is still on port 80. If everything works as you want it, you can easily swap the ports (vhosting on port 80 and IP-based on port 8080)
I already did that on my config.

When you type a wrong url you can direct it to an "oops" page.

To standard webinterface can be easily added to the vhost directory structure using a symbolic link.
My local DNS points mybook.mydomain.com to the IP of the WDMB, so I created this symbolic link
ln -s /usr/www/lib/ /shares/internal/WWW/vhosts/com/mydomain/mybook
When I type mybook.mydomain.com, it will go to the normal admin page. On port 8080 it will always go to the admin page (if you did the swap)

BTW… A nice trick to test virtual hosting on a specific server is configuring your webbrowser to use a proxy (extra => options) and give it the IP and portnumber of the server you are testing. Much easier and better than a hostfile which you might forget to revert to normal. It is this way also impossible to browse normally (I always use Internet Exploder for this and have Firefox do the normal browsing)

Last edited on 1247724094|%e %b %Y, %H:%M %Z|agohover By frater + Show more
Reply  |  Options
Unfold Virtual Hosting, quick and simple by fraterfrater, 1213839583|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
fraterfrater 1224134887|%e %b %Y, %H:%M %Z|agohover

I have a feeling no-one tried this.
It's really powerful and easier to setup than it might look at first glance.

Reply  |  Options
Unfold Re: Virtual Hosting, quick and simple by fraterfrater, 1224134887|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
aab44aab44 1227722774|%e %b %Y, %H:%M %Z|agohover

frater,

in my book the path = /shares/internal/PUBLIC/WWW/vhosts
should i creat WWW under internal forlder or shoul I change evhost.conf to be:

server.document-root ="/shares/internal/PUBLIC/WWW/vhosts/oops/"
server.document-root = "/shares/internal/PUBLIC/WWW/vhosts/%1/%2/%3/"

regarding symbolic link should be like this if my no-ip domain is http://nas-nas.sytes.net

ln -s /usr/www/lib/ /shares/internal/WWW/vhosts/net/sytes/nas-nas
or
ln -s /usr/www/lib/ /shares/internal/PUBLIC/WWW/vhosts/net/sytes/nas-nas

thanks for this nice idea,

Regards,

Reply  |  Options
Unfold Re: Virtual Hosting, quick and simple by aab44aab44, 1227722774|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
fraterfrater 1227735167|%e %b %Y, %H:%M %Z|agohover

In your case you should change the config like this (mine was for a toplevel domain):

cp -p /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.`date +%F`
mkdir /etc/lighttpd/conf.d
[ ! `grep -il conf.d /etc/lighttpd/lighttpd.conf` ] && echo -e "include_shell \"cat /etc/lighttpd/conf.d/*.conf\"" >> /etc/lighttpd/lighttpd.conf

vi /etc/lighttpd/conf.d/evhost.conf

server.modules += ( "mod_evhost" )

$SERVER["socket"] == ":8080" {
server.document-root ="/shares/internal/PUBLIC/WWW/vhosts/oops/"
evhost.path-pattern =  "/shares/internal/PUBLIC/WWW/vhosts/%1/%2/%3/%4/"
}

Create dirs like this:
mkdir -p /shares/internal/PUBLIC/WWW/vhosts/net/sytes/nas-nas/transmission
mkdir /shares/internal/PUBLIC/WWW/vhosts/net/sytes/nas-nas/www
mkdir /shares/internal/PUBLIC/WWW/vhosts/oops
mkdir /shares/internal/PUBLIC/WWW/vhosts/com

and this symbolic link:
ln -s /usr/www/lib /shares/internal/PUBLIC/WWW/vhosts/net/sytes/nas-nas/worldbook

You are then able to host 3 sites:

If you put it in /shares/internal or in /shares/internal/PUBLIC is a matter of taste.
If it's not on the same share as the PUBLIC, you'll be able to restrict access.
I have mine on /shares/internal

Last edited on 1227796937|%e %b %Y, %H:%M %Z|agohover By frater + Show more
Reply  |  Options
Unfold Re: Virtual Hosting, quick and simple by fraterfrater, 1227735167|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
aab44aab44 1227772315|%e %b %Y, %H:%M %Z|agohover

frater,

Thanks for help.

Well, I got it work and assign prot 88, so locally i can access it as http://nas:88

How could I access it from the internet?

I tried http://nas-nas.sytes.net:88 , but it didn't work

Have used boa webserver? is it possible to use it instead of Lighthttp?

note: second line in vhost.confg should be evhost.path-pattern not server.document-root

Thanks for your help and support.
Regards,

Reply  |  Options
Unfold Re: Virtual Hosting, quick and simple by aab44aab44, 1227772315|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
fraterfrater 1227796499|%e %b %Y, %H:%M %Z|agohover

Hi,

That's a different topic and doesn't really have anything to do with your mybook.
You will have to tell your router to do a port-forward to the IP of your mybook.
The port 88 is only there to at least have the standard webpage without any vhosting….

So, any access on your WAN-IP on port 80 should be directed to port 80 of the LAN-IP.
If you've got that right, you will notice that this link will start working:
http://worldbook.nas-nas.sytes.net

If it doesn't work from LAN but it does work from the Internet, it means your router doesn't support "loopback" or it's disabled.

I have no experience with boaserver and don't know its (dis)advantage over lighttpd.
But I do know I would need to find out how this one handles vhosting.
Not worth the trouble I guess….

Last edited on 1227796592|%e %b %Y, %H:%M %Z|agohover By frater + Show more
Unfold Re: Virtual Hosting, quick and simple by fraterfrater, 1227796499|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
gameboyygameboyy 1233608165|%e %b %Y, %H:%M %Z|agohover

hi, thx for reply for the private message, so i reply in here instead. i did everything u said, but I didnt created this symbolic link:
ln -s /usr/www/lib/ /shares/internal/WWW/vhosts/com/mydomain/mybook

Which i think it doesn't have anything to do with any problem i'm facing. Since I'm not setting it up for standard web interface.

I have port 88 opened, and i putted an test index.html into /shares/internal/WWW/vhosts/oops/, or
/shares/internal/WWW/vhosts/com/mytest/mybook/, i tried to go to http://nas:88. it gives me a 404 error page, i tried to go to http://mybook.mytest.com:88, it gives me Failed to Connect. Then i tried http://mybook.mytest.com, there are an already existing page for that URL. I'm really don't know how to make it work now..

Unfold Re: Virtual Hosting, quick and simple by gameboyygameboyy, 1233608165|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
fraterfrater 1233775410|%e %b %Y, %H:%M %Z|agohover

Can you give the output of "netstat -anp | grep http"?
This is mine.

# netstat -anp | grep http
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      640/lighttpd
tcp        0      0 0.0.0.0:8081            0.0.0.0:*               LISTEN      640/lighttpd
unix  2      [ ACC ]     STREAM     LISTENING     673    641/perl            /tmp/lighttpd.fcgi.socket-0

what is the output of ping mybook.mytest.com?

Can't you give real-life examples? I assume you do not own the domain mytest.com.

Unfold Re: Virtual Hosting, quick and simple by fraterfrater, 1233775410|%e %b %Y, %H:%M %Z|agohover
Re: Virtual Hosting, quick and simple
gameboyygameboyy 1233860391|%e %b %Y, %H:%M %Z|agohover

hi,, i can't use your command to check. here's the output:

[root@mybook ~]# netstat -anp | grep http
netstat: illegal option — p
BusyBox v1.2.2 (2007.03.26-11:07+0000) multi-call binary

Usage: netstat [-laenrtuwx]

Netstat displays Linux networking information.

Options:
-l display listening server sockets
-a display all sockets (default: connected)
-e display other/more information
-n don't resolve names
-r display routing table
-t tcp sockets
-u udp sockets
-w raw sockets
-x unix sockets

[root@mybook ~]#

I'm sorry , i was trying things out and got confused. For example,, if my domain is http://xxxx.selfip.com:88
and I want to have my new host name " newhost" , if i understand correctly, my directory structure should be look like this right:

/shares/internal/PUBLIC/WWW/vhosts/com/selfip/xxxx/newhost

From the browser, i should type: http://newhost.xxxx.selfip.com:88 , am i right? if this's the case, it gives me that 404 error, not matter i go to http://xxxx.selfip.com:88 or http://newhost.xxxx.selfip.com:88
I'm using the original lighttpd which comes with Mybook. 1.4.3, don't know if it works with "mod_evhost" , just make sure.
Thanks

Last edited on 1233861056|%e %b %Y, %H:%M %Z|agohover By gameboyy + Show more
Reply  |  Options
Unfold Re: Virtual Hosting, quick and simple by gameboyygameboyy, 1233860391|%e %b %Y, %H:%M %Z|agohover
New Post
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License