Binding domain name to Apache Virtual host on VPS

7,200

This is a formatted comment rather than an answer: is Virtual Hosting configured in your web-server? I.e. (assuming the web-server is apache and you have root access), you should have an entry in /etc/apache2/sites-enabled (which is usually a symlink to /etc/apache2/sites-available/bennyben:

<VirtualHost *:80>
    ServerName bennyben.cz.vhost
    DocumentRoot /home/bennyben/public_html
</VirtualHost>

and also Listen 80 should be there, if it's not in /etc/apache2/ports.conf.

Could you supply your configs?

If anything is not working as expected, don't hesitate to look into /var/log/apache2/error.log.

Share:
7,200

Related videos on Youtube

Lukáš Benke
Author by

Lukáš Benke

Updated on September 18, 2022

Comments

  • Lukáš Benke
    Lukáš Benke over 1 year

    recently company I work for has rented VPS.

    Now i need to have multiple websites hosted on this VPS, that is not a problem, I'v set up virtual hosts, databses, etc. Now i wanted to test it, see if I could access website on the VPS by domain name (bennyben.cz). Domain is registered at different registrar, I've pointed DNS A record to IP address of VPS (193.105.159.72) and it works fine (displays apache default site), but i need to route this domain name (bennyben.cz) to virtual host on the VPS (bennyben.cz.vhost).

    After some googling, I thought that I needed to add new primary DNS zone record (i have ISPConfig installed on VPS) and direct it to virtual host, so i binded the virtual host to local IP address (192.168.1.1) and set A record on VPS to this address, but if i type the domain name, it still serves the default site.

    So my question is, what do i need to host multiple websites with domain names on one VPS (only one WAN IP address available), i did a lot of googling, messed around with BIND, but nothing seems to work.

    System details

    Ubuntu 13.04
    ISPConfig
    1 WAN IP address
    

    P.S. I'm sure this is pretty basic stuff, but I work there as a programmer, so servers aren't my specialization, but, unfortunately we currently do not have anybody who could take care of the VPS, so it has fallen to me.

    Listen 80 
    

    is present in /etc/apache2/ports.conf

    **The vhosts config files are generated for me by ISPconfig*

    Configuration files: /etc/apache2/sites-enabled/100-bennyben.cz.vhost

    <Directory /var/www/bennyben.cz>
        AllowOverride None
        Order Deny,Allow
        Deny from all
    </Directory>
    
    <VirtualHost *:80>
    DocumentRoot /var/www/bennyben.cz/web
    
        ServerName bennyben.cz
        ServerAlias www.bennyben.cz
        ServerAdmin [email protected]
    
        ErrorLog /var/log/ispconfig/httpd/bennyben.cz/error.log
    
        Alias /error/ "/var/www/bennyben.cz/web/error/"
        ErrorDocument 400 /error/400.html
        ErrorDocument 401 /error/401.html
        ErrorDocument 403 /error/403.html
        ErrorDocument 404 /error/404.html
        ErrorDocument 405 /error/405.html
        ErrorDocument 500 /error/500.html
        ErrorDocument 502 /error/502.html
        ErrorDocument 503 /error/503.html
    
        <IfModule mod_ssl.c>
        </IfModule>
    
        <Directory /var/www/bennyben.cz/web>
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/clients/client4/web5/web>
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
    
    
    
    
        # suexec enabled
        <IfModule mod_suexec.c>
            SuexecUserGroup web5 client4
        </IfModule>
        # Clear PHP settings of this website
        <FilesMatch "\.ph(p3?|tml)$">
                SetHandler None
        </FilesMatch>
        # php as fast-cgi enabled
    # For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
        <IfModule mod_fcgid.c>
                FcgidIdleTimeout 300
                FcgidProcessLifeTime 3600
                # FcgidMaxProcesses 1000
                FcgidMaxRequestsPerProcess 5000
                FcgidMinProcessesPerClass 0
                FcgidMaxProcessesPerClass 100
                FcgidConnectTimeout 3
                FcgidIOTimeout 360
                FcgidBusyTimeout 300
                FcgidMaxRequestLen 1073741824
        </IfModule>
        <Directory /var/www/bennyben.cz/web>
                AddHandler fcgid-script .php .php3 .php4 .php5
                FCGIWrapper /var/www/php-fcgi-scripts/web5/.php-fcgi-starter .php
                Options +ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/clients/client4/web5/web>
                AddHandler fcgid-script .php .php3 .php4 .php5
                FCGIWrapper /var/www/php-fcgi-scripts/web5/.php-fcgi-starter .php
                Options +ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
    
    
        # add support for apache mpm_itk
        <IfModule mpm_itk_module>
            AssignUserId web5 client4
        </IfModule>
    
        <IfModule mod_dav_fs.c>
        # Do not execute PHP files in webdav directory
            <Directory /var/www/clients/client4/web5/webdav>
                <ifModule mod_security2.c>
                    SecRuleRemoveById 960015
                    SecRuleRemoveById 960032
                </ifModule>
                <FilesMatch "\.ph(p3?|tml)$">
                    SetHandler None
                </FilesMatch>
            </Directory>
            DavLockDB /var/www/clients/client4/web5/tmp/DavLock
            # DO NOT REMOVE THE COMMENTS!
            # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
      # WEBDAV BEGIN
            # WEBDAV END
        </IfModule>
    
    </VirtualHost>
    

    /etc/apach2/sites-available/bennyben.cz.vhost

    <Directory /var/www/bennyben.cz>
        AllowOverride None
        Order Deny,Allow
        Deny from all
    </Directory>
    
    <VirtualHost *:80>
        DocumentRoot /var/www/bennyben.cz/web
    
        ServerName bennyben.cz
        ServerAlias www.bennyben.cz
        ServerAdmin [email protected]
    
        ErrorLog /var/log/ispconfig/httpd/bennyben.cz/error.log
    
        Alias /error/ "/var/www/bennyben.cz/web/error/"
        ErrorDocument 400 /error/400.html
        ErrorDocument 401 /error/401.html
        ErrorDocument 403 /error/403.html
        ErrorDocument 404 /error/404.html
        ErrorDocument 405 /error/405.html
        ErrorDocument 500 /error/500.html
        ErrorDocument 502 /error/502.html
        ErrorDocument 503 /error/503.html
    
        <IfModule mod_ssl.c>
        </IfModule>
    
        <Directory /var/www/bennyben.cz/web>
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/clients/client4/web5/web>
                Options FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
    
    
    
    
        # suexec enabled
        <IfModule mod_suexec.c>
            SuexecUserGroup web5 client4
        </IfModule>
        # Clear PHP settings of this website
        <FilesMatch "\.ph(p3?|tml)$">
                SetHandler None
        </FilesMatch>
        # php as fast-cgi enabled
    # For config options see: http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html
        <IfModule mod_fcgid.c>
                FcgidIdleTimeout 300
                FcgidProcessLifeTime 3600
                # FcgidMaxProcesses 1000
                FcgidMaxRequestsPerProcess 5000
                FcgidMinProcessesPerClass 0
                FcgidMaxProcessesPerClass 100
                FcgidConnectTimeout 3
                FcgidIOTimeout 360
                FcgidBusyTimeout 300
                FcgidMaxRequestLen 1073741824
        </IfModule>
        <Directory /var/www/bennyben.cz/web>
                AddHandler fcgid-script .php .php3 .php4 .php5
                FCGIWrapper /var/www/php-fcgi-scripts/web5/.php-fcgi-starter .php
                Options +ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
        <Directory /var/www/clients/client4/web5/web>
                AddHandler fcgid-script .php .php3 .php4 .php5
                FCGIWrapper /var/www/php-fcgi-scripts/web5/.php-fcgi-starter .php
                Options +ExecCGI
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
    
    
        # add support for apache mpm_itk
        <IfModule mpm_itk_module>
            AssignUserId web5 client4
        </IfModule>
    
        <IfModule mod_dav_fs.c>
        # Do not execute PHP files in webdav directory
            <Directory /var/www/clients/client4/web5/webdav>
                <ifModule mod_security2.c>
                    SecRuleRemoveById 960015
                    SecRuleRemoveById 960032
                </ifModule>
                <FilesMatch "\.ph(p3?|tml)$">
                    SetHandler None
                </FilesMatch>
            </Directory>
            DavLockDB /var/www/clients/client4/web5/tmp/DavLock
            # DO NOT REMOVE THE COMMENTS!
            # IF YOU REMOVE THEM, WEBDAV WILL NOT WORK ANYMORE!
      # WEBDAV BEGIN
            # WEBDAV END
        </IfModule>
    
    </VirtualHost>
    
    • Jeff Schaller
      Jeff Schaller almost 7 years
      If any of the existing answers solved your problem, please consider accepting it by clicking on the checkmark next to it. Thank you!
  • Lukáš Benke
    Lukáš Benke almost 11 years
    Thanks for quick reply My virtual hosts are correctly set up (193.105.159.72/bennyben.cz) this works. Unfortunately, i cannot provide configuration files because the comments windows says it is too long, should i post it into answer window? Sorry for my ignorance, this is my first question. Thanks
  • CoOl
    CoOl almost 11 years
    @user183162 No problem. Just edit your question and add the new information. To format data as a verbatim file excerpt (like my <VirtualHost>...), leave an empty line and then start each line with 4 spaces.
  • Lukáš Benke
    Lukáš Benke almost 11 years
    I've edited my original question, do you need anything else?
  • CoOl
    CoOl almost 11 years
    Thanks. (Besides, I believe /etc/apache2/sites-enabled/100-bennyben.cz.vhost is just a symlink for /etc/apach2/sites-available/bennyben.cz.vhost, so it's just a duplication. Read permissions to your .vhost files are, probably, ok... And .vhost configs seem reasonable to me.
  • CoOl
    CoOl almost 11 years
    Hey, but with these settings you are not serving any index.html, right? So, when you just type http://bennyben.cz in the address line, apache shouldn't serve anything (it would've served index.html, but it doesn't exist in your var/www/bennyben.cz/web). I've typed in http://bennyben.cz/index.html and got Internal Server Error. So everything seems ok. Try adding a static html page, e.g. "index.html" to your /var/www/bennyben.cz/web and check if it gets served. http://bennyben.cz/index.php gave me internal server error, too. So, see the error log.
  • Lukáš Benke
    Lukáš Benke almost 11 years
    I have created directory var/www/bennyben.cz/web and uploaded index.html file, still 500 error, but in error log is this: [Fri Jul 26 16:53:11 2013] [crit] [client 83.208.254.144] configuration error: couldn't perform authentication. AuthType not set!: / I will do some googling and leave a comment if I find something interesting
  • Lukáš Benke
    Lukáš Benke almost 11 years
    Thanks a lot for your effort and also, I've learned a little about how to post on SO. Many thanks and have a nice day :)
  • CoOl
    CoOl almost 11 years
    @user183162 No worries, glad it's working!