Score:0

Configuring Virtual Hosting Httpd - Fedora Server - 'sites-available and sites-enabled' vs 'conf.d/vhost.conf'

cv flag

The current set-up for my web server is a 1GB nanode using Fedora37 as the distribution for the compute instance. For the web server I am using Httpd (Apache 2.4.54), and am now in the process of configuring virtual hosting. I have read several different guides on Linode and other sites. Some of them say to configure virtual hosting in:
/etc/httpd/sites-available/example.com.conf and /etc/httpd/sites-enabled/example.com.conf,
while others suggest putting all non-standard configuration files in /etc/httpd/conf.d/ putting virtual hosting in /etc/httpd/conf.d/vhost.conf

I found another conversation on this topic here at server fault at Difference in sites-available vs sites-enabled vs conf.d directories (Nginx)?. However, it is in regards to nginx which I am not using and there was no clear answer. Also, the question was asked 9 years ago, so I am wondering if anything has changed since then.

I originally set up the virtual hosting in sites-available and sites-enabled as per this guide on Linode:https://www.linode.com/docs/guides/how-to-install-apache-web-server-centos-8/#configure-virtual-hosting It is for CentOS, but the steps should be generally compatible with Fedora.

However, then I ran into this guide: https://www.linode.com/docs/guides/lamp-server-on-fedora-20/ which uses the vhost.conf method. The guide is for setting up a LAMP server on Fedora, which I would like to do.

My question is, where should I put my configuration files for virtual hosting? What would be the 'best practice' in this case? Do I need to set up the configuration in both places? If I wanted to set up a LAMP server, would I have to use the vhost.conf method? Are these methods interchangeable?

Please let me know if there is any additional information needed in order to answer the question. Thank you for your time and patience - catbyte

us flag
I don't have any hands-on experience with neither CentOS or Fedora. But you can check how the main Apache configuration file is set up and which files is included.
CatByte-io avatar
cv flag
@TeroKilkanen - Do you mean that it should have come preconfigured? Please clarify what you mean by 'main Apache configuration file'. Thank you.
us flag
Yes, the distribution has main Apache2 configuration file, which then has include statements for the auxiliary configuration files. For example, in Debian the main Apache configuration file is at `/etc/apache2/apache2.conf`, and `IncludeOptional` statements that include other configuration files.
Score:0
cv flag

I had done a lot of research before asking this question and was certain I couldn't figure it out, but I believe I did. Thanks to this guide on enabling and disabling websites, https://www.linode.com/docs/guides/how-to-enable-disable-website/, the process became a lot more clear.

It might depend on who you ask, but it looks like there isn't one that is more effective or correct than the other, and either method can be used with any distribution. The biggest difference I can see between the two lies in how websites are disabled and enabled.

The method of virtual hosting in /etc/httpd/sites-available/example.com.conf and /etc/httpd/sites-enabled/example.com.conf is usually used by Debian and Ubuntu distributions, but can be used by other distributions as well if it has been configured. A symlink from the /etc/httpd/sites-enabled/ directory must be made to the vhost file in /etc/httpd/sites-available/ in order to enable a website. The vhost file being /etc/httpd/sites-available/example.com.conf

The method of virtual hosting in /etc/httpd/conf.d/vhost.conf can be used by any distribution as well. To disable a website on the Apache server, you can enter the file and add a # in front of each line in the configuration so it is not active. Or, if you are able to use a2ensite and a2dissite tools, use a2ensite example.com to enable a website and a2dissite example.com to disable.

There are other variations as well. I just saw one guide that directs you to configure virtual hosting in /etc/httpd/vhost.d/example.com.conf

It seems to me that you just need to choose a method, and not set up configurations in both places.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.