VirtualHost Targeting With Include Files
This is the article that explains this. You can target specific vhosts by placing the include file in the /etc/apache2/conf.d/userdata folder. These are the parameters that you can target: Apache version, SSL or non-SSL, user, domain, and global vhosts. Here are the example configurations:
ALL vhosts (ALL Apache versions)
/file.conf
Non-SSL vhosts (ALL Apache versions)
/std/file.conf
SSL vhosts (ALL Apache versions)
/ssl/file.conf
SSL vhosts (2.4 Apache version)
/ssl/2_4/file.conf
User's vhosts (ALL Apache versions)
/user/file.conf
Non-SSL user domain.com's vhosts (ALL Apache versions)
/std/user/domain.com/file.conf
Now, this is the theory and according to it all these should work, but I've tried some and they don't, for example, the last one from the list.
I kinda suspect that Apache is not fond of the global include file variants (without the specified Apache version). Is there a reason why other includes don't get included?
-
Hey hey! Can you let me know specifically what you've tried to enter there that isn't working? The include system has been in place for a very long time, and I'm not aware of any issues with the files just not being read.
1 -
Hey! Let me do a few more tests and I'll get back to you with exact specifics.
0 -
These are the results of testing:
/ssl/file.conf <== NOT included
/ssl/2_4/file.conf <== includedSo, include files without the Apache version in the path do not get included in httpd.conf.
Also, this doesn't work as well. I don't know if this is even a functionality, to modify both SSL and non-SSL hosts under the same user:
/user/file.conf
0 -
That seems like it would be the correct behavior - if it's not one of the Apache versions, it's more of a "for your own reference" type of thing.
Let's look at the actual Apache conf. At the end of each vhost, we have this include file listed, along with a corresponding comment:
Include "/etc/apache2/conf.d/userdata/std/2_4/username/domain.com/*.conf"
# To customize this VirtualHost use an include file at the following location
# Include "/etc/apache2/conf.d/userdata/std/2_4/username/domain.com/*.conf"so if you aren't using a file inside /etc/apache2/conf.d/userdata/std/2_4/username/domain.com/, I wouldn't expect it to be added.
The SSL vhost shows corresponding data, just with the "std" replaced with the "ssl" path:
Include "/etc/apache2/conf.d/userdata/ssl/2_4/username/domain.com/*.conf"
# To customize this VirtualHost use an include file at the following location
# Include "/etc/apache2/conf.d/userdata/ssl/2_4/username/domain.com/*.conf"so I would expect you to need to customize both, depending on what you are doing, and if you want it applied to both the secure and insecure vhost.
As an example, WP Toolkit places an include file both the 80 and 443 vhosts include directory for each domain:
[root@host]# ll /etc/apache2/conf.d/userdata/std/2_4/username/domain.com/
total 12K
drwxr-xr-x 2 root root 4.0K Feb 17 2023 .
drwxr-xr-x 3 root root 4.0K Feb 17 2023 ..
-rw-r--r-- 1 root root 1.7K Feb 17 2023 wp-toolkit.conf
[root@host]# ll /etc/apache2/conf.d/userdata/ssl/2_4/username/domain.com/
total 12K
drwxr-xr-x 2 root root 4.0K Jan 1 22:44 .
drwxr-xr-x 3 root root 4.0K Feb 17 2023 ..
-rw-r--r-- 1 root root 1.7K Feb 17 2023 wp-toolkit.conf1 -
Thank you for the analysis Rex,
that is exactly my experience and conclusion. At least we know now.
0 -
You're welcome!
1
Please sign in to leave a comment.
Comments
6 comments