Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Thu Aug 27, 2009 8:47 pm 
Offline
Senior Newbie

Joined: Wed Aug 26, 2009 11:58 am
Posts: 6
Location: Wales, UK
With apache it is relatively easy but I am finding lighttpd to be extremely frustrating. I have found several sites including the linode library that explain how to set a vhost/subdomain up, but for the life of me I cannot do it. Maybe it's an awkward thing to explain but I'm finding documentation on this subject around the web to be lacking in clarity. As a result I am finding setting up a vhost in lighttdp to be frustrating and convoluted, in my novice experience of course.

I haven't yet registered my domain name, so I am still accessing my site via my IP address until it is all sorted. http ://my_ip_addy takes me to where I want to go. My cms however is located out side my web root and I would like to set up a subdomain for it i.e http ://subdomain.my_ip_addy.

Could someone please explain to me how I might get such a thing to work.

Code:

$HTTP["host"] == "subdomain.my_ip_addy" {
    server.document-root = "/path/to/subdomain/files"
}


The above doesn't work. I have also tried the Simple vHost setup located here, to no avail. I find it very confusing. My linode setup has gone largely without a hitch surprisingly for me and this one thing that should be quite straight forward has as taken the majority of my time to sort out. Any help would be greatly appreciated as this is just driving me insane now.

Final note (just popped into my head). If I wanted to keep the url of my cms more secure or secret, could a vhost be setup to take me to a domain that is something other than that of my main website. So instead of:

Code:
w ww.myDomain.com - main site
http://cms.myDomain.com - cms access point


I could have:
Code:
w ww.myDomain.com - main site
http://cms.myOtherDomain.com - cms access point


Or should I just restrict access to the cms to my PCs IP address?


Top
   
PostPosted: Fri Aug 28, 2009 2:17 am 
Offline
Senior Member
User avatar

Joined: Sun Jan 18, 2009 2:41 pm
Posts: 830
lew0810 wrote:
I haven't yet registered my domain name, so I am still accessing my site via my IP address until it is all sorted. http ://my_ip_addy takes me to where I want to go. My cms however is located out side my web root and I would like to set up a subdomain for it i.e http ://subdomain.my_ip_addy.

The way name-based virtual hosting works, you cannot access sites with different names/subdomains by typing an IP address into the browser's address bar. You need to fool your machine (the one you're sitting in front of, not your Linode) into thinking that the name(s) you're planning on giving it resolve to the Linode's IP address. For example, if your Linode's IP is 11.22.33.44 and you want to have sites hosted on it at foo.example.net and bar.example.net, you'd add the following line to your desktop machine's /etc/hosts file:
Code:
11.22.33.44   foo.example.net bar.example.net

Once you have DNS properly set up for the new site (or to access the "real" site with those names), you should delete or comment out this line.


Top
   
 Post subject:
PostPosted: Fri Aug 28, 2009 10:08 am 
Offline
Senior Member

Joined: Wed Feb 13, 2008 2:40 pm
Posts: 126
Quote:
http ://subdomain.my_ip_addy


The Internet doesn't work that way.


Top
   
PostPosted: Fri Aug 28, 2009 10:25 am 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
Vance wrote:
The way name-based virtual hosting works, you cannot access sites with different names/subdomains by typing an IP address into the browser's address bar. You need to fool your machine (the one you're sitting in front of, not your Linode) into thinking that the name(s) you're planning on giving it resolve to the Linode's IP address.

Yup. Another way is to cheat totally and use "telnet", which may be sufficient to determine that the vhost functionality works
eg
Code:
 % telnet 1.2.3.4 80
Trying 1.2.3.4...
Connected to 1.2.3.4
Escape character is '^]'.
GET / HTTP/1.0
Host: virtual.host1


The blank line is important. Then you should get the home page for "virtual.host1" showing up. Do the telnet again with different Host: lines and you should get the other home pages.

(The web server just uses the Host: header to determine what virtual host to use; your web browser normally sends this).

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
 Post subject:
PostPosted: Fri Aug 28, 2009 10:28 am 
Offline
Senior Member
User avatar

Joined: Sun Feb 08, 2004 7:18 pm
Posts: 562
Location: Austin
sweh, wouldn't that have to be HTTP 1.1, not 1.0? I think it's 1.1 that allows you to specify the domain you're looking for, enabling name-based hosting.


Top
   
 Post subject:
PostPosted: Fri Aug 28, 2009 10:39 am 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
Requests using HTTP/1.1 MUST provide a host header. HTTP/1.0 doesn't require it (but also doesn't deny it). I've not come across a web server which does Host: based virtual servers which doesn't work with the 1.0 header. There might be some out there, but I've not found one :-)

lighttpd, specifically, works just fine with 1.0 in the header line.

_________________
Rgds

Stephen

(Linux user since kernel version 0.11)


Top
   
 Post subject:
PostPosted: Fri Aug 28, 2009 4:21 pm 
Offline
Senior Newbie

Joined: Wed Aug 26, 2009 11:58 am
Posts: 6
Location: Wales, UK
Thanks for your replies. I now have my domain registered, setup and showing me my site at example.com but I still can't get the subdomain to work:

$HTTP["host"] == "subdomain.example.com" {
server.document-root = "/var/subdomain/"
}

I'm just not getting it. Do all subdomains have to be located within the same folder as the public web root (/var/webroot/)? I'm still after something like http://subdomain.example.com


Top
   
 Post subject:
PostPosted: Fri Aug 28, 2009 6:13 pm 
Offline
Senior Newbie

Joined: Wed Aug 26, 2009 11:58 am
Posts: 6
Location: Wales, UK
I've been doing some digging and found that simple-vhosts configuration doesn't occurr in the lighttpd.conf file but in the conf-available/10-simple-vhost.conf file instead. At least this is how it appears as every time I tried to configure simple-vhost in lighttpd.conf it said there was some sort of conflict when I tried to restart the server. Anyway this is what I have in conf-available/10-simple-vhost.conf:


simple-vhost.server-root = "/var/vhost/"
simple-vhost.default-host = "cms.example.com"
simple-vhost.document-root = "/"



My understanding of this is when cms.example.com is requested simple-vhost will search for the files within the server-root + default-host + document-root as so:

/var/vhost/cms.example.com/

At which point it should server the pages it finds. Is this correct as it still wont work?


Top
   
 Post subject:
PostPosted: Fri Aug 28, 2009 11:24 pm 
Offline
Junior Member

Joined: Tue Apr 27, 2004 11:46 pm
Posts: 30
What won't work, and how won't it work?

What exactly happens when you point your browser to your subdomain?
Do you get any errors? if so, what are they?
What do the log files for lighttpd show? are they showing access to the proper vhost?

Lighttpd is fairly simple to configure. Its not that hard.


Top
   
 Post subject:
PostPosted: Sat Aug 29, 2009 4:49 am 
Offline
Senior Member
User avatar

Joined: Sun Mar 23, 2008 10:10 am
Posts: 71
Website: http://frontseed.com/
Lighttpd is really simple to configure. My practice is to put each vhost into a separate file, e.g. in /etc/lighttpd/vhosts:
Code:
drwxr-xr-x 2 root root 4096 Aug 25 10:48 .
drwxr-xr-x 5 root root 4096 Jul  4 12:33 ..
-rw-r--r-- 1 root root 1239 Jul 29 12:27 ecample.com.conf
-rw-r--r-- 1 root root 1553 Jul  6 12:05 otherdomain.com.conf
-rw-r--r-- 1 root root 1023 Aug  2 10:49 anotherdomain.net.conf


and I have my last line in lighttpd.conf:
Code:
include_shell "cat /etc/lighttpd/vhosts/*.conf"


Then each vhost file contains something similar:
Code:
$HTTP["host"] =~ "^(|www\.)example\.com$" {
    # redirect from www to non-www domain
    $HTTP["host"] =~ "^www\.example\.com$" {
        url.redirect = ( "^/(.*)" => "http://example.com/$1" )
    }
    server.name = "example.com"
    server.document-root = "/websites/example/content.example.com/"
    accesslog.filename = "/websites/example/log/example.com_access.log"

### custom vhost settings go here
    $HTTP["url"] =~ "\.(png|jpe?g|gif|js|css)$" {
        expire.url = ( "" => "access 14 days" )
    }
    url.access-deny = ( "~", ".inc", ".myotherfiles-that-needs2be-denied" )
    #etc etc.
}


I usually keep a 'template' for this vhost and tweak them for my needs. If I need something with my defaults, I just copy the template and replace all 'example' to 'mydomain' and it's done.
If I want to remove a vhost, I just simply rename the [hostname].conf to something like [hostname].conf.off and reload lighttpd.

Of course you need all your virtual hosted domains to point your server IP.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group