nginxrhel8

how to add/override a new nginx configuration file?


I have a somedomain.com.conf file under /etc/nginx/sites-available in linux (RHEL). if i want to host a web app/site, do i just edit the same file or create a new configuration file for nginx? I edited this file and it works, but trying to find the right way to do this. is the convention , create a new config file for each site/app, you host?

server {
    listen 80;
    server_name mysite.com;

    charset utf-8;
    root /var/www/mysite-folder;
    index index.html index.htm;

    location / {
            root /var/www/mysite-folder;
            try_files $uri /index.html;
    }
}

Solution

  • I thought the RHEL-based systems doesn't make use of that sites-enabled/sites-available mechanism at all (in opposite to Debian-based distros). Of course, the most common approach is to use a separate files for each hosted domain name (maybe including the subdomains). All those files are being included from the top level configuration file /etc/nginx/nginx.conf at the http context level; the Debian packages usually have

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

    lines in that file while RHEL packages usually have only the single

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

    line. As you can see files in the sites-enabled directory may be named any way while files in the conf.d directory should have the .conf extension to be included (and you can rename it so something like <donain>.off to temporary exclude from nginx configuration). What directory to use for your vhost configuration is up to you (I personally prefer to use /etc/nginx/conf.d/ since it is a more universal way). There is a big Difference in sites-available vs sites-enabled vs conf.d directories thread on this subject on ServerFault (the whole question is more suited for ServerFault rather that StackOverflow; please next time ask this kind of question there).