Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have some experience using linux but none using nginx. I have been tasked with researching load-balancing options for an application server.

I have used apt-get to install nginx and all seems fine.

I have a couple of questions.

What is the difference between the sites-available folder and the conf.d folder. Both of those folders were INCLUDED in the default configuration setup for nginx. Tutorials use both. What are they for and what is the best practice?

What is the sites-enabled folder used for? How do I use it?

The default configuration references a www-data user? Do I have to create that user? How do I give that user optimal permissions for running nginx?

share|improve this question
Try to avoid scope creep when asking a question; www-data is a separate topic. Most operating systems define a separate user with lower permissions that the process can run as after binding to port 80 as root. It's defined in the config file. Apply basic security practices from there; don't let the user write to anything the webserver shouldn't need to write to, don't let other users write to the files unless it's deliberate. – Andrew B Jul 31 '13 at 15:14
Please, accept an answer! – Nikos Alexandris Dec 6 '15 at 12:55

The sites-* folders are managed by nginx_ensite and nginx_dissite. For httpd users who find this with a search, the equivalents is a2ensite/a2dissite.

The sites-available folder is for storing all of your vhost configurations, whether or not they're currently enabled.

The sites-enabled folder contains symlinks to files in the sites-available folder. This allows you to selectively disable vhosts by removing the symlink.

conf.d does the job, but you have to move something out of the folder, delete it, or make changes to it when you need to disable something. The sites-* folder abstraction makes things a little more organized and allows you to manage them with separate support scripts.

(unless you're like me, and one of many debian admins who just managed the symlinks directly, not knowing about the scripts...)

share|improve this answer
Did I get something wrong? Not understanding the downvote. – Andrew B Aug 9 '13 at 13:27

Typically, the sites-enabled folder is used for virtual host definitions, while conf.d is used for global server configuration. If you're supporting multiple web sites -- i.e., virtual hosts -- then each one gets its own file, so you can enable and disable them very easily by moving files in and out of sites-enabled (or creating and removing symlinks, which is probably a better idea).

Use conf.d for things like module loading, log files, and other things that are not specific to a single virtual host.

The default configuration references a www-data user? Do I have to create that user?

You should have nginx running as a non-root user. This is in some cases named www-data, but you can name it anything you want.

How do I give that user optimal permissions for running nginx?

I'm less certain of the answer to this question (I'm not running nginx at the moment), but if it's anything like Apache the answer is that the www-data user only needs read execute to any static files that you're serving, or read/execute permissions on things like CGI scripts, and no permissions anywhere else.

share|improve this answer
having a dedicated user for running web server is also important due to disable login capability for this user by removing valid shell record. – DukeLion Aug 9 '13 at 13:02

I would like to add to the previous answers that the most important is not how you call the directories (though that is a very useful convention), but what you actually put in nginx.conf. Example configuration:

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

The only directive used here is include, so there is no internal difference between e.g. conf.d/ and sites-enabled/.

From the documentation above:

Syntax:     include file | mask;
Default:    —
Context:    any

Includes another file, or files matching the specified mask, 
into configuration. Included files should consist of 
syntactically correct directives and blocks.

So, to answer the original question: there is no internal difference, and you may use them in the best way you can, remembering advice from the other answers. And please, don't forget to choose the 'right' answer.

share|improve this answer
On Stack Exchange sites, all an accept means is that it solved the problem for the person who asked. This is why it's not uncommon to come across answers that have much higher scores than the ones which are accepted. The person who asked this question is more than welcome to change their mind, but please keep in mind that it's misguided to suggest that the accepted answer be changed. (it's a very subjective thing) – Andrew B Apr 16 '15 at 23:34
@andrew-b Yes, but in this post there is no accepted answer, though they all solve the problem. I noticed that people usually ask to accept an answer, so I thought that it's better for the system when there are accepted answers than otherwise. – Yaroslav Nikitenko Apr 17 '15 at 8:43
Right, sites-enabled has been somewhat invented by some ditribution, fuzzing around as an annoying intermediate does. Go grab nginx from the official source: you will get an up-to-date product, as well as getting rid of this configuration crap/hell. – Bernard Rosset Apr 4 at 16:10

Your Answer


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.