how to create a sub domain in linodemanager and host it
Do I need to do it both on the linode manager and as well as in the nginx?
In nginx do I have to treat it as a complete new site and create a new file under "sites-available" and "site-enabled" directories ?
or do i modify the nginx file for the same domain and add a mapping to point it to a different directory.
Can someone provide some instructions on how to complish this ?
5 Replies
@sri12:
i need to create a subdomain and configure my nginx to support it. how do I do it, looking up some articles are very confusing.
- Do I need to do it both on the linode manager and as well as in the nginx?
If your domain's DNS is configured via the Linode Manager, yes. You'll need to have an "A" record in the DNS for example.com for subdomain.example.com to work. This will allow the rest of the world to find the IP address of the web server.
> - In nginx do I have to treat it as a complete new site and create a new file under "sites-available" and "site-enabled" directories ?
- or do i modify the nginx file for the same domain and add a mapping to point it to a different directory.
It's up to you… nginx doesn't care either way. I would tend to put it in its own file, since it makes it easier to find the configuration the next time you need to change it. If it is just a redirect, e.g.
The sites-* directories are set up for your benefit, to make it easier for you (or some other sysadmin) to find a site's configuration quickly. So, don't be afraid to use it.
how do I edit the existing site config file to point
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
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
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
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 servernameshashmaxsize)
Config I have looks like this
server {
listen 80;
server_name www.domain.com domain.com *.domain.com;
access_log /srv/www/domain.com/logs/access.log;
error_log /srv/www/domain.com/logs/error.log;
location / {
root /srv/www/domain.com/public_html;
index index.html index.htm;
}
location /phpmyadmin { root /usr/share; index index.php; }
location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/domain.com/public_html$fastcgi_script_name;
}
Note that your existing configuration has *.domain.com as a server_name… I'm not sure how this will interact with foo.domain.com, but I think I've seen something about this case in the nginx documentation.