: Should Apache's httpd.conf Main Server configuration be used with virtual hosts? Apache's httpd.conf file has three sections. Section 2 is for the 'Main' server configuration, and Section 3 is
Apache's httpd.conf file has three sections. Section 2 is for the 'Main' server configuration, and Section 3 is for Virtual Hosts. In section 2, one has the option to give their server a name. In the past, I always filled this section out regardless of whether I am also using VirtualHosts.
ServerName mysite.com DocumentRoot "/var/www/html/"
Recently, I found my VirtualHost wasn't working as I expected. Later I found that the Section 2 configuration was taking precedent over the VirtualHost using the same ServerName. I had thought that the VirtualHosts would extend the second section, however, it doesn't seem to be the case.
When using VirtualHosts, should ServerName not be filled out (or left as example.com) in Section 2?
More posts by @Martha676
1 Comments
Sorted by latest first Latest Oldest Best
For future readers, there are several builds of Apache one for each of the major *inux instances out there and there are differences between them. One of the major differences is whether Apache is using httpd.conf where it is primarily configured as a single site web server or using apache2.conf where it is primarily configured for virtual hosts. Personally, I prefer the latter, but both are fine. But what happens is that the builds using httpd.conf primarily configured as a single site occasionally confuses people. It is actually how Apache used to be built before the change. I am not sure where the confusion comes in, but I rather suspect that having different sets of instructions on the net may have something to do with it. For the record, if you have httpd.conf, it may pay to reference older Apache documentation regarding configuration at times but not forgetting what is depreciated/changed by referring to the new documentation.
In this case, the OP seems to be creating virtual sites below the original single site. Each section would use the directive ServerName. Without looking at his configuration specifically, there seems to be a conflict between the original single site and one of the virtual sites.
There are two options for solving his problem.
1] Commenting out the ServerName within the single site configuration since there seems to be some confusion there. It may be likely that this entire section should be commented out.
--or--
2] Configure the original single site as a catch-all site.
Since this is an answer based upon comments, the OP commented out the ServerName in the original single site configuration which solved his problem. This is option 1. In the comments, I referred to www.tecmint.com/apache-ip-based-and-name-based-virtual-hosting/ as a resource that might help the OP. In all of the help I found on the net, none of them seemed to refer to this problem directly.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.