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.
For some reason new Nginx's configuration file doesn't include file /etc/nginx/sites-available/default. That was my problem.
This is old but if you can't figure out the answer take a look at Config Changes Not Reflected on the nginx wiki.
Try to clear your browser cache and see if the changes are reflected. As soon as I cleared my browser cache the "Welcome to Nginx" page never loaded again.
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 towww.somedomain.com
like this: