What is the difference between sites-enabled and sites-available directory?

折月煮酒 提交于 2019-12-18 09:57:02

问题


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


回答1:


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 Apache2 Virtual Hosts. Virtual Hosts allow Apache2 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 here https://help.ubuntu.com/lts/serverguide/httpd.html




回答2:


Important information:

You should edit files only in sites-available directory.

Do 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 to start. If your site was working, it will not be anymore. 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.




回答3:


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 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 in sites_available. Changes apply automatically in sites_enabled, through the symlink. Just remember reload Apache.



来源:https://stackoverflow.com/questions/21812360/what-is-the-difference-between-sites-enabled-and-sites-available-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!