Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I just installed nginx version 1.2.5 on a new server and discovered that I can not change the default file for default website.

In /etc/nginx/sites-available/default file I have the following lines:

server {
listen 80 default_server;
    server_name myserver;
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    root /var/www/default;
error_page 404 /4044.html;
    location / {
        index index.html index.htm;
    }

}

server {
... server2...
}
server {
... server3...
}

Unfortunately, when I open a page by using server's IP address http://ip_address, instead of file /var/www/default/index.html nginx displays it's default file "Welcome to nginx". In case of 404 error it doesn't display the file /var/www/default/4044.html but it's default "not found"page.

I tried to change: listen 80 default_server; to listen 80 default; and server_name myserver; to server_name servers_ip_address

restarted nginx, but no success. Checked error.log file but nothing wrong. I have nginx installed on 2 more servers but olders versions of nginx. There are no problems like this.

Any ideas? If I cannot change its, does anyone knows wher default pages are located so that I can edit them? Thanks.

share|improve this question
    
Are you sure, that you have symlink to this file in /etc/nginx/sites-enabled? –  VBart Nov 17 '12 at 13:04
add comment

2 Answers

up vote 0 down vote accepted

For some reason new Nginx's configuration file doesn't include file /etc/nginx/sites-available/default. That was my problem.

share|improve this answer
    
well thats a debian specific behaviour. sites-available holds all your configuration files and sites-enabled holds all active configuration files. So to enable a site just use: sudo ln -s /etc/nginx/sites-available/default /etc/nginx/sites-enabled/ –  rbtux Nov 20 '12 at 18:50
add comment

The is the correct behaviour based on your configuration. Then you load the IP address of the server, you will always get the first virtual server definition for that IP address, since nginx cannot determine the server name from the HTTP header.

If you want another server block to respond, simply move it to the first position for that IP address.

The HTML files fo the default server are located in /var/www/default, which is defined by the "root" directive (root /var/www/default;)

Having a default configuration for an IP is actually quite useful. I use it to automatically redirect from non www. address to www.somedomain.com like this:

server {
listen 192.168.1.1 default;
server_name "_";
root /usr/local/nginx/html/whaever;
if ($host ~* ^[^.]+\.[^.]+$) { rewrite ^(.*)$ http://www.$host$1 permanent; }
}
share|improve this answer
1  
gmck, that's the problem. If I load the IP I don't get the first virtual server definition. As I wrote, the document root for first virtual server is /var/www/default but nginx shows it's own default file "welcome to nginx". It's not the file that I have in /var/www/default. I want to know how to get rid of "welcome to nginx" file when I load server's IP. –  user1821484 Nov 17 '12 at 14:14
    
@gmck, you're doing it wrong: nginx.org/en/docs/http/converting_rewrite_rules.html and wiki.nginx.org/Pitfalls –  VBart Nov 17 '12 at 16:14
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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