Why is setting up a subdomain for lighttpd so confusing...
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 ://myipaddy 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.myipaddy.
Could someone please explain to me how I might get such a thing to work.
$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
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:
w ww.myDomain.com - main site
http://cms.myDomain.com - cms access point
I could have:
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?
9 Replies
@lew0810:
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 ://myipaddy 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.myipaddy.
The wayworks, 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 name-based virtual hosting: /etc/hosts file
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.
> http ://subdomain.myipaddy
The Internet doesn't work that way.
@Vance:
The way
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. name-based virtual hosting
Yup. Another way is to cheat totally and use "telnet", which may be sufficient to determine that the vhost functionality works
eg
% 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).
lighttpd, specifically, works just fine with 1.0 in the header line.
$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 h
simple-vhost.server-root = "
simple-vhost.default-host = "
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:
At which point it should server the pages it finds. Is this correct as it still wont 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.
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:
include_shell "cat /etc/lighttpd/vhosts/*.conf"
Then each vhost file contains something similar:
`$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.[/url]