Go Premium for a chance to win a PS4. Enter to Win


Apache - Ubuntu - Virtual hosts

Posted on 2012-12-21
Medium Priority
Last Modified: 2013-02-04
I have Virtual hosts set up on Ubuntu/Apache.
The domain names for my sites are working fine.
But if I type in the IP address of my server I get the apache default page.
What do I need to put in the apache conf file to direct the IP address of the server to display a site on my server.
Do I need to create a whole new <VirtualHost *.80>  block or do I enter something in the current <VirtualHost *.80> block?
Question by:nachtmsk
  • 2
  • 2

Expert Comment

ID: 38713200
Your conf file should have something like this for the configuration.

<VirtualHost ipAddress:80>
ServerName domain.com
ServerAlias www.domain.com
ServerAdmin name@domain.com
DocumentRoot /var/www/"file location"

The main important part is the ipAddress and DocumentRoot. If you would like a tool to better help you manage the server webmin is free and works great on ubuntu.

If you plan on running multiple websites from the same server you'll need to look into setting up a MultiSite Layout.

Author Comment

ID: 38713237
Thanks, but where/how do I put in the IP address of the server so it directs to a virtual site and not the default Apache site?

Expert Comment

ID: 38713298
It sounds like the issue that you're running into is the document location is wrong. Find where you are saving the web files and add that document location.

Changing the <Directory /var/www/> to your location should work if you're only running one website on the server.

You will have to restart apache or the server when making changes.

sudo service apache2 restart or sudo /etc/init.d/apache2 restart

What kind of access do you have to the server?

Author Comment

ID: 38714009
I have root access. Think I just solved it. I put in a server alias of the IP address. The problem I was trying to solve is that the IP address was going to the default location while the virtual  hosts (domain names) were going to the correct location. I wanted the IP address (if put into a browswer) to go to one of my virtual hosts.

Accepted Solution

nam0a earned 2000 total points
ID: 38750915
Put the first site in the first virtual host entry

    DocumentRoot "/var/www/html/site1"
	ServerAlias www.example.com
	ServerAdmin root@example.com
    ServerName example.com

    DocumentRoot "/var/www/html/site2"
    ServerName example2.com
	ServerAlias www.example2.com
	ServerAdmin root@example2.com

Open in new window

here site1 is the fist site that is to be redirected when the user type the IP address.
also make sure DocumentRoot is set to the correct site /var/www/html/site1

DocumentRoot "/var/www/html/site1"

Featured Post

Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to demonstrate how we can use conditional statements using Python.
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses
Course of the Month9 days, 2 hours left to enroll

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question