If you're looking to do a redirect, so that it'll say
http://example.com/foo/ in their address bar,
Code:
server {
listen 80;
server_name foo.example.com;
location / {
rewrite ^/(.*)$ http://example.com/foo/$1 permanent;
}
}If you want it to exist "on its own", you'd set it up as a
normal virtual host, just like example.com's configuration, but with the root as the subdirectory. The snippet here is ripped almost verbatim from the library article linked above:
Code:
server {
listen 80;
server_name foo.example.com;
access_log /srv/www/example.com/logs/foo-access.log;
error_log /srv/www/example.com/logs/foo-error.log;
location / {
root /srv/www/example.com/public_html/foo;
index index.html index.htm;
}
}Be mindful of any configuration that might need to be carried over from example.com's config to foo.example.com, like fastcgi_pass or logging stuff.
If you're doing it this way, you'll probably also want to add a redirect from
http://example.com/foo/ to
http://foo.example.com/, so that there is one and only one canonical URL for the content. Into example.com's config,
Code:
location /foo {
rewrite ^/foo(.*)$ http://foo.example.com$1 permanent;
}
(A quick note about the usage of rewrite here: The first argument to rewrite is a
regular expression that matches on the pathname part of the URL, so
http://example.com/foo/bar is /foo/bar,
http://example.com/ is /, etc. The "(.*)" says "grab everything between here and the next match and shove it into $1", and the "$" at the end represents the end of the line.)
I haven't tested these configuration snippets, but I did look at a working configuration template when writing them, so they're written with love. -rt (you haven't lived until you've had to increase server_names_hash_max_size)
_________________
Code:
/* TODO: need to add signature to posts */