What is the difference between the 'sites-enabled' and 'sites-available' directory? [closed]
Asked Answered
S

3

165

What is use of these two directories in Apache 2 and how can we do it?

Selangor answered 16/2, 2014 at 14:18 Comment(1)
serverfault.com/questions/83508/…Reginareginald
S
132

The difference is that virtual sites listed in the sites-enabled directory are served by Apache. In the sites-available directory there are the virtual sites that exist on your server, but people can't access them because they are not enabled yet.

sites-available: this directory has configuration files for Apache 2 Virtual Hosts. Virtual Hosts allow Apache 2 to be configured for multiple sites that have separate configurations.

sites-enabled: like mods-enabled, sites-enabled contains symlinks to the /etc/apache2/sites-available directory. Similarly when a configuration file in sites-available is symlinked, the site configured by it will be active once Apache2 is restarted.

See https://help.ubuntu.com/lts/serverguide/httpd.html.

Stipendiary answered 16/2, 2014 at 14:23 Comment(6)
Should I edit files in sites-enabled or in sites-available ?Bryant
@Bryant you should edit files in sites-availableStipendiary
if those are symlinks, it doesn't matter which one you editRoo
@Roo Actually it matters, if you are using nano editor. See my answer for details.Puma
The links seems to be dead.Maser
The link is effectively broken (redirects to a generic page, Ubuntu Server Guide).Jeremy
P
119

Important information

If you are still using sites-available/sites-enabled pattern, you should edit files only in the sites-available directory.

Never edit files inside the sites-enabled directory. Otherwise you can have problems if your editor runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM.

For example: if you are using nano to edit the file sites-enabled/default and it runs out of memory or, for any reason, it receives a SIGHUP or SIGTERM, then nano will create an emergency file called default.save, inside the sites-enabled directory.

So, there will be an extra file inside the sites-enabled directory. That will prevent Apache or nginx from starting. If your site was working, it will not be any more. You will have a hard time until you find out, in the logs, something related to the default.save file and, then, remove it.

In the example above, if you were editing the file inside the sites-available directory, nothing bad would have happened. The file sites-available/default.save would have been created, but it wouldn't do any harm inside the sites-available directory.


Update

The sites-enabled/site-available pattern is deprecated, according to The Complete NGINX Cookbook in NGINX official site.

The /etc/nginx/conf.d/ directory contains the default HTTP server configuration file. Files in this directory ending in .conf are included in the top-level http block from within the /etc/ nginx/nginx.conf file. It’s best practice to utilize include state‐ ments and organize your configuration in this way to keep your configuration files concise. In some package repositories, this folder is named sites-enabled, and configuration files are linked from a folder named site-available; this convention is deprecated.

Instead of using sites-enabled/site-available pattern, just add a your-site.conf under the /etc/nginx/conf.d folder.

Puma answered 10/1, 2017 at 12:18 Comment(2)
Well, you need to restart your webserver anyway in order for the action to take effect, thus, even if the editor added that extra file, your webserver will ignore it unless you restart the webserver.Isochronal
@Isochronal Once you have the extra file, you won't be able to star/restart the webserver whenever you need. That is the problem.Puma
L
13

You configure your site mysite by creating or editing the file mysite.conf in sites-available (you can also configure several sites in the same .conf file, if you prefer).

After this, for publishing the site you must create the correspondent symlink in folder sites-enabled. In Ubuntu you can do it like this:

a2ensite mysite (with sudo, if necessary; and without the final .conf)

And then you must reload Apache:

sudo service apache2 reload

Later, if you want to modify the configuration, you only touch the mysite.conf file in sites_available. Changes apply automatically in sites_enabled, through the symbolic link. Just remember to reload Apache.

Laise answered 21/11, 2019 at 22:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.