How to host multiple webites on Apache

Can any one please let me know how to host multiple websites on single linux machine with apache web server.

Take for example.

I have three websites registered

www.abc.com
www.cde.com
www.xyz.com

I would like to host all three 3 real websites on single centos Box with Apache.

What are the configurations that needs to be changed in server end & at domain registrar end
sivaatluriAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dan CraciunIT ConsultantCommented:
# Ensure that Apache listens on port 80
Listen 80

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/abc
ServerName www.abc.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/cde
ServerName www.cde.com

# Other directives here

</VirtualHost>

<VirtualHost *:80>
DocumentRoot /www/xyz
ServerName www.xyz.com

# Other directives here

</VirtualHost>

Open in new window


Make the A (address) record for www.abc.com, etc on the DNS point to the server's IP and you're set.

https://httpd.apache.org/docs/2.2/vhosts/examples.html

HTH,
Dan

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sivaatluriAuthor Commented:
Can I put different port numbers for each site..?

If so what should I do at domain end as well as server end
Dan CraciunIT ConsultantCommented:
You can do this:
# Ensure that Apache listens on port 80, 81, 82
Listen 80
Listen 81
Listen 82

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:80>
DocumentRoot /www/abc
ServerName www.abc.com

# Other directives here

</VirtualHost>

<VirtualHost *:81>
DocumentRoot /www/cde
ServerName www.cde.com

# Other directives here

</VirtualHost>

<VirtualHost *:82>
DocumentRoot /www/xyz
ServerName www.xyz.com

# Other directives here

</VirtualHost>

Open in new window


You would access the sites with www.xyz.com:82, of course, so I don't know why you would want to do that.

You don't have to change nothing on the DNS end for using different ports.
Dave BaldwinFixer of ProblemsCommented:
Dan's right, if the 'NameVirtualHost' are set up correctly, you don't need to use separate ports.  DNS for all of them can point to the same IP address.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.