Skip to main content

Creating My VirtualHosts to Apply Directives

Comments

8 comments

  • cPRex Jurassic Moderator

    Hey there!  If you just need a virtualhost for them to exist for **reasons** could you just create a subdomain through cPanel?  That would create the hostname and then you could customize the individual vhosts using the details here in a way that would only affect the individual domains:

    https://docs.cpanel.net/ea4/apache/modify-apache-virtual-hosts-with-include-files/

    0
  • vatra

    I can't; I need to create separate VHs for those subdomains because the settings I apply to them are separate from those of their apex domain. The only way to do that is to create them myself in the pre_virtualhost_global.conf.

    0
  • cPRex Jurassic Moderator

    If you create a subdomain it gets an separate vhost entry with a separate customization area.  Here's one I created just now to confirm:

      # To customize this VirtualHost use an include file at the following location
    # Include "/etc/apache2/conf.d/userdata/std/2_4/username/sub.domain.com/*.conf"

    Would that not work since it's completely separate from the main domain.com?

    0
  • vatra

    OK, my mistake, you're right, but I still need to create the one for the server hostname and NSs. Plus, sometimes I need to modify just the ServerName domain without its ServerAlias domains.

    0
  • vatra

    Plus, I need them to be able to override the default ones.

    0
  • cPRex Jurassic Moderator

    There's no reason you can't create a subdomain for the server's hostname - you just may need to remove existing DNS entries first if they are hosted locally.

    If you want to do it fully manual like you outlined I don't see why it shouldn't work.  The only conflict you'd run into is if you forget in the future and try to make another change related to one of those domain names, but that would give you some type of "already exists" error during the Apache rebuild process.

    0
  • vatra

    Manual works perfectly, I just need an experienced eye to look at all of this and see if something can be improved or prevented.

    For example, is it a good tactic to make SH a default for all IPs:

    <VirtualHost 127.0.0.1:80 [serverIP]:80 [dedicatedIP1]:80 [dedicatedIP2]:80 *:80>
    <VirtualHost 127.0.0.1:443 [serverIP]:443 [dedicatedIP1]:443 [dedicatedIP2]:443 *:443>
    0
  • cPRex Jurassic Moderator

    Sure, I don't see any issues with that.

    0

Please sign in to leave a comment.