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/*;
  • are you trying to set up virutal host functionality?
    – SLY
    Feb 3 '11 at 20:41
  • I want access my host using my.mydomain. etc.
    – Neo
    Feb 3 '11 at 20:46
  • One interesting observation. http://mycomputername works. So somehow there is a command like 'server_name $hostname' somewhere over-riding my rule.
    – Neo
    Feb 3 '11 at 22:33
  • Did you find a solution? I'm having the exact same problem but on OSX. Basically all of my server configs only work on localhost / mycomputername, no matter what the server_name is set to Jan 2 '13 at 3:36
  • A valid hostname cannot contain a period!
    – mdpc
    Jan 2 '13 at 5:36

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.

  • root in location / is bad form. It won't be available in any other locations. Please read wiki.nginx.org/Pitfalls
    – kolbyjack
    Feb 3 '11 at 20:52
  • @kolbyjack - Thats ok, I will be doing proxy_pass anyway. But I just wanted to get the first step working.
    – Neo
    Feb 3 '11 at 20:53
  • @daveadams ( Doesn't work. I'll be adding my configuration files to original question.
    – Neo
    Feb 3 '11 at 20:57
  • @kolbyjack, thanks for pointing that out. I agree it's sloppy form. @Neo, is your mine.enpass config file symlinked in sites-enabled? If so, are you using "mine.enpass" in your web browser to access it? If yes to both, then I'm stumped without more info.
    – daveadams
    Feb 3 '11 at 21:12
  • @daveadams - I followed your steps exactly. localhost 'still' works. But mine.enpass doesn't :(. I can attach nginx.conf as well.
    – Neo
    Feb 3 '11 at 21:19

try changing server_name mine.enpass ; to server_name mine.enpass; in your sites-available/mine.enpass file

  • no luck. I'm able to make even proxy_pass work. But can't change the server_name!!
    – Neo
    Feb 3 '11 at 22:21
  • I honestly don't know where could be the problem, include /etc/nginx/sites-enabled/*; is the last line in the http {}, so there shouldn't be a chance for any other files/configs to override your server_name...
    – addam
    Feb 3 '11 at 22:49
  • addam: Im pretty sure nginx does not read and apply configuration from top to bottom.
    – 3molo
    Jun 19 '11 at 12:06

Is it possible you have not added mine.enpass to your /etc/hosts file?

This was the basic mistake I made, having the same issues with nginx but in OSX (stumbled upon the solution here)

  • mine.enpass is NOT a valid hostname!
    – mdpc
    Jan 2 '13 at 5:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.