What Steps are need to host a Website on Ubuntu using Apache2?

29

If you have multiple sites on one Apache httpd server, you should post the complete configuration (both VirtualHost).

I'm going to post an example config of a two site Apache server, one which serves to www.example.com and one for www.example.org:

file: /etc/apache2/sites-available/example-com

<VirtualHost 172.20.30.50>
DocumentRoot /var/www/example.com/
ServerName www.example.com

# Other directives here ...

</VirtualHost>

file: /etc/apache2/sites-available/example-org

<VirtualHost 172.20.30.50>
DocumentRoot /var/www/example.com/
ServerName www.example.com

# Other directives here ...

</VirtualHost>

If both your sites point to: localhost, only one site will show, one precedes the other, in other words, has a higher priority. That's wha the "ServerName" directive is there for. It will serve those who try to ener that ServerName.

So if you're only testing things on your localhost, just use the same VirtualHost and use subfolders. One site in: /var/www/site1 and the other in /var/www/site2, and point your browser to: http://localhost/site1 or http://localhost/site2.

Another solution if you don't want to have subfolders in your URL is to bypass your DNS lookup and just force some domain lookups throught the /etc/hosts file. Here is an example (You want to add to the 127.0.0.1 line at the end):

file: /etc/hosts

127.0.0.1 localhost example.com example.org

Your /etc/hosts file might look different, just remember to add the two domains to the end because as I explained earlier, Apache will only serve you one VirtualHost to the same ServerName.

For more information: http://httpd.apache.org/docs/2.2/vhosts/examples.html

Share:
29

Related videos on Youtube

Kpuonyer
Author by

Kpuonyer

Updated on September 18, 2022

Comments

  • Kpuonyer
    Kpuonyer over 1 year

    I'm trying to write a simple password system for my website. No username, nothing like that, just a password I can distribute to friends. The idea is to pass a value to the small CGI program written in C below:

    #include <stdio.h>
    #include <stdlib.h>
    int main(){
    char *test;
    printf("Content-Type: text/html\n\n");            //give the content type
    test = getenv("QUERY_STRING");                    //get the data
    //printf ("%s\n\n", test);                        //print it for debugging purposes
    if (test == "test=test") {                        //check for correct password
        printf("<a href=\"home.html\">Enter.</a>");   //give the link if correct
    }
    else if (test == NULL){
        printf("Error.");
    }
    else{
        printf("Denied.", test);
    }
    return(0);
    }
    

    The problem is that, no matter what is passed to it, it always prints "Denied". Whenever I print the returned data, it is exactly what I would expect, i.e. "test=test", yet it still prints "Denied". I'm pretty sure I'm doing this correctly, and I wonder if it is a problem with the server (TinyWeb). The HTML form code is below:

    <form action="cgi-bin/cgi.exe" method="get">
        <input name="test" placeholder="Password">
        <input type="submit" value="enter">
    </form>
    
    • Achu
      Achu over 10 years
      You need to specify your server name for you second vhost. like ServerName yoursecondwebsite.de
    • Private
      Private over 10 years
      i just saw that as well and addet it. still doesn't work
    • Achu
      Achu over 10 years
      have you added the name of the new site under /etc/hosts?
    • Private
      Private over 10 years
      I added my site 127.0.0.1 mywebsite to hosts, yes. I also added Servername mywebsite to my config. thats my full content of that configuration :)) above