Nginx: how to add new site/server_name in nginx

nginx

I'm just starting to explore Nginx on my Ubuntu 10.04. I installed Nginx and I'm able to get the "Welcome to Nginx" page on localhost. However I'm not able to add a new server_name, even when I make the changes in site-available/default file. Tried reloading/restarting Nginx, but nothing works. One interesting observation. "http://mycomputername" in browser works. So somehow there is a command like 'server_name $hostname' somewhere over-riding my rule.

File: sites-available/mine.enpass

server {
   listen   80;
   server_name  mine.enpass ;

   access_log  /var/log/nginx/localhost.access.log;

   location / {
    root   /var/www/nginx-default;
    index  index.html index.htm;
   }
}

File: nginx.confg

user www-data;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
worker_connections  1024;
# multi_accept on;
}

http {
include       /etc/nginx/mime.types;

access_log  /var/log/nginx/access.log;

sendfile        on;
#tcp_nopush     on;

#keepalive_timeout  0;
keepalive_timeout  65;
tcp_nodelay        on;

gzip  on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types      text/plain text/css application/x-javascript text/xml application/xml    application/xml+rss text/javascript;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}

Best Answer

My recommendation is to remove the default site by removing the symlink in /etc/nginx/sites-enabled:

$ sudo rm /etc/nginx/sites-enabled/default

Then create your desired configuration in a new file, call it /etc/nginx/sites-available/your.host.name. Assuming you have your home page at /var/www/your.host.name, here's a very simple example:

server {
        listen 80;
        server_name your.host.name;

        location / {
                root   /var/www/your.host.name;
                index  index.html;
        }
}

Then create a symlink in /etc/nginx/sites-enabled:

$ sudo ln -s /etc/nginx/sites-available/your.host.name /etc/nginx/sites-enabled/your.host.name

Finally, restart nginx:

$ sudo /etc/init.d/nginx restart

Good luck.