101 Virtual Hosting for Dummies
  • Have you ever installed your airtime on say your webserver and found that you no longer can access your website.

    You go to the wiki and WoW  :-B after you do all that it says and yet still you cannot access your site.

    Welcome aboard.
    I cried when it first happen,then I re-install and still I am back to square one. (like Déjà vu)


    So yes ,Your answer lies in Virtual Hosting,but after borrowing a book on apache from the 
    Library,rack up some late fees trying to understand it and darn! I am confused. :-&

    This is why 101 Virtual Hosting for Dummies is to the rescue.

    Most book and the wiki will tell assume that your webroot ( DocumentRoot) is /var/www/ 

    and so 101 Virtual Hosting for Dummies will try to explain virtual hosting in general and where the webroot ( DocumentRoot) are either the same or different

    This tutorial is focus on using one Apache server with Many host

    Its not meant to be the Authoritative source but form a foundation to start on.

    Please Refer to Apache site and other documentation for further understanding (see below)
    also see  what could go wrong (troubleshooting) at the end of this tutorial if it does not work


    Preambles 

    if you 
    cat /etc/apache2/ports.conf

    you will see
     
    NameVirtualHost *:80
    Listen 80


    And if you do a
    /etc/apache2# cat /etc/apache2/sites-available/airtime-vhost.conf

    your first line should read some thing like this
    <VirtualHost *:80>
          ServerName localhost

    This means that whatever you set as virtual host will always directed to airtime.

    your solution can be  and should be on any on any of the many option of virtual hosting configuration ( my only assumption here is that you want a robust solution and not just a symbolic link to the webroot ( DocumentRoot).

    My favorites are 

    1-   Separate ports   - Single Network card  - A fixed IP is recommended (my preference for small environments)

    2-   Mixed name-based -single Network card  - you need a fixed IP for your server

    3-   Separated IP  - for this you need at least 2 network cards (my preference for large heavy traffic environments)

    :-B  
    Post edited by Voisses Tech at 2013-12-19 22:39:07
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  • 11 Comments sorted by
  • Seperate ports   -single Network card  - A fixed Ip is recommended

    With different ports assignment
    This is somewhat a prefered method (IMHO) and Require least configuration

    First you need to assigned your ports to your site and so you need to
    do a ports configuration for your apache server to listen on. in ubuntu its found at
    /etc/apache2/ports.conf

    I will have

    My site Listen on Port 80  (default and already in configuration file)
    Airtime Listen on Port 8080
     
    so edit your ports.conf and put  (MUST BE DONE)

    Listen 8080

    now lets configure your Airtime web interface to use this port

    edit the following 3 files  and change the ports 80 to port 8080

    pico /etc/airtime/api_client.cfg and 
    pico /etc/airtime/airtime.conf 
    pico /etc/apache2/sites-available/airtime-vhost.conf 

    To Accept Changes
    service apache2 reload

    now go to 

    http://localhost:8080 and you should see your airtime

    http://localhost and you should see your site.



    Post edited by Voisses Tech at 2014-03-06 08:27:18
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  • Mixed name-based -single Network card  - you need a fixed IP for your server

    This method relies upon DNS Name resolution and its preferred that you have a
    DNS server
    Change your virtual host configuration in your sites-available to read like this

     removed the *:80 and replace the with IP
                 
    <VirtualHost 192.168.2.22>
         ServerName airtime
         #Fill in other information here
    </VirtualHost>

    <VirtualHost 192.168.2.22>
      ServerName mysite
      #Fill in other information here
    </VirtualHost>


    Please fill in the other information ,

    what I am showing here is the key is the Servername and the change of the virtual host


    To Accept Changes
    service apache2 reload

    YOU MIGHT HAVE TO CONFIGURE YOU HOSTS (/etc/hosts) ON THE SERVER TO RESOLVED THIS NAME

    Now you can use http://airtime

    Post edited by Voisses Tech at 2013-12-19 22:07:36
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  •  Separate IP  - for this you need at least 2 network cards

    This is another good method especially if you wants to monitor traffic on a
    particular interface.
    I think this suited to be employed in production environments. 

    The Procedure is same as a Mixed Name but you will now configure the sites available
    with separate IP based on your interface configuration

    <VirtualHost 192.168.2.22>
         ServerName airtime
         #Fill in other information here
    </VirtualHost>


    <VirtualHost 172.20.30.40>
        DocumentRoot /www/example3
        ServerName   mysite
    </VirtualHost>

    To Accept Changes
    service apache2 reload


    Depends on your level of paranoia
    You could employ 

    Mixed interface with different ports.

    So for better reading visit these sites


    Post edited by Voisses Tech at 2013-12-19 22:43:59
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  • What could Go wrong? (FAQ)

    You are not seeing your site or Airtime?

    1. You may need to refresh your browser to remove cache.Its best to close the browser and reopen.
    2. You forgot to put in the different ports,like in our example airtime is on localhost:8080 or IP address of the interface 192.168.2.22
    3. You did not reload your apache server.Apache looks at sites-enable for web directions.In ubuntu sites-enable is a symbolic link to sites-available and once you change your sites-available information and reload the information is updated in sites-enable. Check that both information match after a reload
    4. You forget to enable your sites sudo a2ensite mysite and then reload.At times you may want to disable the default site to find out what is going on sudo a2dissite mysite and then reload

    Now There are many other things that can go wrong but check the Var/logs and it will tell you a lot.

    Tips for paranoid and have a good machine
    • Install your firewall ,if you are a geek shorewall is your thing
    • Install an intrusion system like snort.
    • and never forget fail2ban.

    When you look at your logs you might be amazed.

    Thanks for reading,Hope this will be of help

    VOISSES
    Post edited by Voisses Tech at 2013-12-19 22:44:20
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  • If you have 14.04,Apache configuration has change where you have to now define each host and Airtime has change now so you have to use https to log in
    so here are the changes to get to get you on track if you use your computer for more than one application or service

    Please note that steps are the same above and you can use it as a guide for more advance configuration

    VOISSES
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  • first create your virtual host for your webserver or any other service you
    you can copy the  airtime virtual host for *80  and then place it below that one

    You are now going to create your own custom virtual host
    Read this https://wiki.apache.org/httpd/DirectoryListings
    to Understand the changes I will make below

    Optional
    ______________________
    You will be require to
    Change the ServerName if you have sub-domainNames like mysub.domain.new


    Required
    ---------------------
    but you must

    1.Change the DocumentRoot    the default is localhost,if you change make sure you setup your host
    2.Change the DirectoryIndex  you can change this to what you want typically index.html or index.php
    3.Change the Directory       since Trusty the default is /var/www/html but typically its /var/www/
    4.Delete the directive Redirect You can redirect to wherever you want but you delete this if not necessary
    5.Setup an Options for Indexes The default is +Indexes which allows anyone to see a listing of all files and directory via the webinterface
     

    <VirtualHost *:80>
          ServerName localhost

          ServerAdmin root@localhost

          DocumentRoot /var/www/
          DirectoryIndex index.html index.htm index.php welcome.html



          SetEnv APPLICATION_ENV "production"

          <Directory /var/www/>
                  Options -Indexes
                  AllowOverride All
                  Require all granted
          </Directory>
    </VirtualHost>


    make sure you have one of the directory index file (index.html index.htm index.php welcome.html)
    in the directory root unless you will get an error


    Monit and RabbitMq require to run on http services but

    Its best and advantageous to run Airtime on a different port
     

     sudo pico /etc/apache2/ports.conf      set up your new listen port like (8080)
     sudo pico /etc/airtime/api_client.cfg  change the base Port
     sudo pico /etc/airtime/airtime.conf    change the base Port  
     sudo pico /etc/apache2/sites-available/airtime-vhost.conf  change the *80 to a new port (8080)
     
    if you created a new domain or subdomain you will need to enable that site

     sudo a2ensite mysub.domain.new
     
     sudo service apache2 restart

    VOISSES

    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.
  • Voisses -- I <3 you but why in the world would anyone want to deliberately run Airtime on a (virtual) machine that isn't dedicated?? Directing public traffic to an Airtime server is nuts!
  • Kudos!
  • An easier way to do this in Apache 2.4+ is to...

    1. Write in other vhosts in the /etc/apache2/sites-enabled/airtime-vhost.config
    2. Add "Include /etc/apache2/sites-enabled/your_other_site.config" to /etc/apache2/sites-enabled/airtime-vhost.config

    You may need to a2enmod a few things....

    (I am not questioning it, it works for me and I can even share port 443 and a multi-domain certificate. Just be sure to set ServerName to a FQDN... sub.domain.tld)

    sudo apt-get update
    sudo apt-get upgrade
    sudo install -y build-essential libapache2-mod-proxy-html libxml2-dev
    sudo a2enmod proxy
    sudo a2enmod proxy_http
    sudo a2enmod proxy_ajp
    sudo a2enmod rewrite
    sudo a2enmod deflate
    sudo a2enmod headers
    sudo a2enmod proxy_balancer
    sudo a2enmod proxy_connect
    sudo a2enmod proxy_html
    sudo a2enmod proxy_wstunnel
    sudo a2enmod xml2enc
    sudo a2enmod ssl
    sudo service apache2 restart
    Do ports al a @Voisses instruction if you wish to use non-standard ports... But for standard ports, as long as everything is served or reverse proxy through apache2, and you use unique ServerNames, they play along... If using a wildcard SSL, use your private ip.... i.e.... <VirtualHost 192.168.0.1:443> this is also suggested with multi-domain ssl, but not necessary on a subdomain level through my experience.
    Post edited by Odin Wynd at 2017-04-29 13:35:53
  • If liquidsoap starts harping on you for it.....

    sudo nano /etc/hosts

    127.0.0.1 subdomain.domain.tld subdomain

    (you can also use your private ip instead of 127.0.0.1)

    Edit:

    On boot, liquidsoap still complains about errno 111, however... running airtime-check-system shows everything is ok.... Everything runs fine in the scheduler... unsure if the is just a bug or what...
    Post edited by Odin Wynd at 2017-04-29 13:37:53
  • Vote Up0Vote Down Voisses TechVoisses Tech
    Posts: 1,423Member
    The way I refer was my preferred way and maybe old  I answer why here

    https://forum.sourcefabric.org/discussion/comment/35513#Comment_35513

    and should fix you problem
    Post edited by Voisses Tech at 2017-05-01 03:06:57
    Anyone reading this a find it funny about my grammar , I make no apology ,Go get a translator.
    "The Problem with education today is that it takes a university degree to switch on a light bulb"
    "You learn from your mistakes but wise people learn from others mistakes avoid Making mistakes there is not sufficient rooms to make them"
    "Innuendo","If's","Assumptions" and "Fear" are for politician.Who,What,where,When and How are for those seeking knowledge and care about Humanity.
    "I might be in Mud but that does not Make me a Wild Hog(pig)"
    “Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius — and a lot of courage to move in the opposite direction.”
    "The only thing that remains constant is change itself"
    May the force be with you,until our path or destiny bring us in tandem.