Results 1 to 5 of 5

Thread: Howto: Run multiple websites (users) from one docroot

  1. #1
    Join Date
    Jun 2016
    Posts
    43

    Howto: Run multiple websites (users) from one docroot

    Weve build a web application which must serve different domains. At the moment we are using domain pointers (with alias) and this works fine. The thing is we want to be able to attach different SSL certificates to the domains, want to keep resources per user and also be able to manage DNS. What Ive tried is the following:

    Added a new user of one of the domains, F.E. newdomain.com

    In custom HTTPD I added the following for newdomain.com:

    |*if SSL_TEMPLATE="1"|
    |?DOCROOT=/home/user/domains/basedomain.com/private_html|
    |*else|
    |?DOCROOT=/home/user/domains/basedomain.com/public_html|
    |*endif|

    These docroot is from the base domain. At the moment this does not work, I get the following error:

    Mismatch between target UID (1004) and UID (1002) of file "/home/user/domains/basedomain.com/public_html/index.php"

    This is of course right but I try to find a way to solve this.

    I matched PHP versions for basedomain.com and newdomain.com

    Our server uses apache/2 with Cloudlinux with fastcgi configured in DA.

    Any ideas?

  2. #2
    Join Date
    Jun 2016
    Posts
    43
    Hi Alex, thx for your reply. I do not really understand what you mean by mount --bind , could you explain? And maybe you have other thoughts? What I would like is:

    - Have one domain for our codebase (basedomain.com)
    - Have multiple users the use the same codebase but with own domain
    - Separate SSL certificates
    - DNS per domain
    - Resources per user

    Basically that comes down to domain pointers (alias) but then without the shared resources of one user.

  3. #3
    Join Date
    Jun 2019
    Posts
    81
    If you are wanting to use different certificates for the domain names, but both point to the same DocumentRoot, perhaps you would be better off creating the newdomain as a domain under the user panel (not as a domain pointer).

    This will create a separate VirtualHost for newdomain separate from basedomain.

    This will also create a separate directory for newdomain to use as DocumentRoot:

    /home/user/domains/newdomain.com

    But if you want this to be the same as

    /home/user/domains/basedomain.com

    Couldn't you just delete /home/user/domains/newdomain.com and set up /home/user/domains/newdomain.com as a symlink to /home/user/domains/basedomain.com

    rm -rf /home/user/domains/newdomain.com
    ln -s /home/user/domains/basedomain.com /home/user/domains/newdomain.com


    (As always, be careful with rm -rf as this is going to delete the entire /home/user/domains/newdomain.com directory, I'm assuming it's empty, but if it's not or if there is something in there that you want to keep, don't run this command without moving those files out of the directory structure first)

    Now you would have a VirtualHost to install a certificate on for basedomain.com and a VirtualHost to install a certificate for newdomain.com - but they would both draw their content from /home/user/domains/basedomain.com

    (This is why I don't like "domain pointers" or "domain aliases")

  4. #4
    Join Date
    Jun 2016
    Posts
    43
    @sparek. Thank you for your reply and ideas. I've tried this but I get the message: Forbidden - You don't have permission to access / on this server.

    The server log for newdomain says:
    AH00037: Symbolic link not allowed or link target not accessible: /home/user/domains/newdomain.com

    I think this has to do with user:group rights. Since the new user tries to access scripts from another user:group

    If you have any further ideas, please let me know.

  5. #5
    Join Date
    Jun 2019
    Posts
    81
    Unfortunately it's not immediately clear what specifically you are doing.

    Quote Originally Posted by anton1982 View Post
    Weve build a web application which must serve different domains.
    Where is this application hosted? What file-system path on the server is this code stored at?

    For example, if this is being stored under the path:

    /var/www/html/mywebapp

    Then perhaps you just need to create a rewrite.

    <Location /mywebapp>
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{SERVER_PORT} ^80$ [OR]
    RewriteCond %{HTTP_HOST} !=%THESERVERSHOSTNAME%
    RewriteCond %{REQUEST_URI} ^/mywebapp
    RewriteRule ^ https://%THESERVERSHOSTNAME%/mywebapp [R=302,L]
    </IfModule>
    </Location>


    (Replace %THESERVERSHOSTNAME% with the actual server's hostname... or the domain name for whatever account is hosting this application on the server)

    Within one of the Apache include files (perhaps /etc/httpd/conf/extra/httpd-alias.conf).

    This way when any domain name that resolves to the server (anydomain.com) uses a URL structure like http://anydomain.com/mywebapp - they get redirected to https://%THESERVERSHOSTNAME%/mywebapp

    This alleviates the need for every anydomain.com to have to have it's own secure certificate. And it insures that the application is executed under the correct user owner.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •