Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx including conf from conf.d but still loading default settings

All configurations are being included and conf test is passed too. But Nginx is still serving the default HTML from /usr/share/nginx/html, instead of location root from conf file in conf.d directory.

conf file from conf.d directory

upstream django {
    server          unix:///tmp/server.sock;
}

server {
    listen          80;
    server_name     server.test.com;
    access_log      /srv/source/logs/access-nginx.log;
    error_log       /srv/source/logs/error-nginx.log;

    location / {
        uwsgi_pass      django;
        include         /srv/source/conf/uwsgi/params;
    }

    location /static/ {
        root            /srv/source/;
        index           index.html index.htm;
    }

    location /media/ {
        root            /srv/source/media/;
        index           index.html index.htm;
    }

    # alias favicon.* to static
    location ~ ^/favicon.(\w*)$ {
        alias /srv/source/static/favicon.$1;
    }

}
like image 728
rayman Avatar asked Jun 03 '16 21:06

rayman


1 Answers

The default nginx config is in /etc/nginx/nginx.conf. By default that file includes the following lines (at least that is the case on rhel based and arch based distros):

include /etc/nginx/conf.d/*.conf;

server {
    listen       80 default_server;
    listen       [::]:80 default_server;
    server_name  _;
    root         /usr/share/nginx/html;

    # Load configuration files for the default server block.
    include /etc/nginx/default.d/*.conf;

    location / {
    }

    error_page 404 /404.html;
        location = /40x.html {
    }

    error_page 500 502 503 504 /50x.html;
        location = /50x.html {
    }
}

Thanks to the root in the server section nginx will keep serving the files under that directory until you comment our these lines. This happens just after conf.d is loaded (as noted in the snippet above).

No matter what you change inside conf.d that last part of the file will still be loaded. Since it is that file (/etc/nginx/nginx.conf) that loads the configs in conf.d.

And yes, you definitely should comment out that default server if you plan to use nginx.

like image 86
grochmal Avatar answered Oct 24 '22 08:10

grochmal