The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Add ServerAlias to all/some accounts?

Discussion in 'EasyApache' started by eminos, May 12, 2017.

  1. eminos

    eminos Member

    Joined:
    Oct 26, 2011
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    51
    cPanel Access Level:
    Root Administrator
    Hi!

    I would like to add a ServerAlias to all or some user domains. I've been looking through the docs and Googled a lot but couldn't find an easy solution for what seems to be a simple task.

    My goal is to be able to access the websites via a "preview" subdomain of my "main domain".
    I could add a *.preview.myhostingcompany.com DNS entry.

    I need this because I find the current way, server.myhostingcompany.com/~username, is not always working well with some applications.

    I would like to either:

    1. Add the ServerAlias (username.preview.hostingcompany.com) for all accounts automatically (old and new accounts).

    or

    2. Being able to manually add that ServerAlias for specific user domains. Preferably via htaccess (although this might be a security risk and is maybe not even possible?).

    It seems both these ways (either all domains, or some selected domains) involves config files or template files on the server.

    Using the ".local" template files seems to have the downside that I could miss important updates to the default template when cPanel updates. (And it seems using the .local files is EA3 only?)

    And setting up custom vhost overrides for specific accounts will be cumbersome since I will need this all the time (while developing a new website and showing it to customers).

    Using one include file in /etc/apache2/conf.d/userdata also doesn't provide the variables as the templates in /var/cpanel/templates have. So I couldn't setup custom ServerAlias for each vhost that way.

    Is there no easier way to accomplish this? I'm using EA4.
     
    #1 eminos, May 12, 2017
    Last edited: May 12, 2017
  2. eminos

    eminos Member

    Joined:
    Oct 26, 2011
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    51
    cPanel Access Level:
    Root Administrator
    The closest thing to a solution I've been able to find is to park the subdomain (username.preview.myhostingcompany.com) on the user domain via WHM. That could be a solution for my needs BUT it doesn't seem to work properly and it seems to have messed up the httpd.conf file!

    Now I have unparked the subdomain but the VirtualHost for the user is now right at the bottom of the httpd.conf below "Define the main cPanel & WHM proxy subdomains".

    Code:
    ##################################################
    ##################################################
    #
    # Define the main cPanel & WHM proxy subdomains
    #
    ##################################################
    ##################################################
    
    NameVirtualHost 123.123.123.123:80
    NameVirtualHost 123.123.123.123:443
    <VirtualHost 123.123.123.123:80>
      ServerName userdomain.se
      ServerAlias mail.userdomain.se www.userdomain.se
      DocumentRoot /home/userdomain/public_html
    ......
    Maybe this issue is serious? Maybe even a cPanel bug?

    And maybe it's related to that the server hostname is server6.myhostingcompany.com and at the same time I have a user that uses that main domain (myhostingcompany.com).
     
    #2 eminos, May 12, 2017
    Last edited: May 12, 2017
  3. eminos

    eminos Member

    Joined:
    Oct 26, 2011
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    51
    cPanel Access Level:
    Root Administrator
    Now I've manually run /usr/local/cpanel/scripts/rebuildhttpdconf and the httpd.conf seems to be back to normal.

    So what could have been wrong here? I parked and unparked that preview subdomain from WHM, and it messed up httpd.conf.
     
  4. cPanelJasonT

    cPanelJasonT Level 2 Technical Analyst
    Staff Member

    Joined:
    Oct 21, 2014
    Messages:
    55
    Likes Received:
    6
    Trophy Points:
    83
    cPanel Access Level:
    Root Administrator
    Hello,
    I believe that the user include should be effective for what you are trying to do.
    The ServerAlias directive supports multiple entries for one vhost. However, if you are trying to utilize an additional hostname for the same Alias and document root, the thing you want to is to use an Alias in cPanel.
    This is essentially the same as Parking a domain in WHM and is the best way to keep the hosting manageable from cPanel.
    Documentation for this feature is available here:
    Aliases - Version 64 Documentation - cPanel Documentation
     
  5. Anoop P Alias

    Anoop P Alias Well-Known Member

    Joined:
    Mar 31, 2015
    Messages:
    65
    Likes Received:
    6
    Trophy Points:
    8
    Location:
    Kochi,Kerala,India
    cPanel Access Level:
    Root Administrator
    You may be able to edit the apache vhost template too in /var/cpanel/templates/apache2_4/
     
  6. eminos

    eminos Member

    Joined:
    Oct 26, 2011
    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    51
    cPanel Access Level:
    Root Administrator
    Sorry but none of your answers really answers my question. Or maybe I wasn't clear enough.

    To create the Alias that I need I need to enable the possibility to add Aliases on OTHER users domains in Tweak settings in WHM. Which is, of course, a big security issue, so that's not really an option. Also, when I do it that way I get that messed up httpd.conf described above. Would be interesting to hear if this is the expected behavior or a bug (see code snippet in OP .. doesn't look right?).

    To edit the Apache vhost template, yes, I can do that, which I also mentioned in my first post (although not very clear, I wrote about the .local template, which should override the default vhost template). This solution works as expected, BUT then I need to follow up on changes that are made to that template with new cPanel versions.

    My question was if there is a solution that doesn't have those problem described above.
    It seems there is no better way, but to just edit the vhost template and keep checking if cPanel makes any changes to it with every major (or even minor) update...
     
  7. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    37,171
    Likes Received:
    1,295
    Trophy Points:
    363
    cPanel Access Level:
    Root Administrator
    Hello,

    Could you open a support ticket using the link in my signature so we can take a closer look at the affected system's Apache configuration file when adding the alias? You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
Loading...

Share This Page