How to configure multiple IP addresses for apache virtual hosts

Source: Internet
Author: User
Tags comments php tutorial phpmyadmin

How to configure multiple IP addresses for apache virtual hosts


Enable the VM configuration file

Set httpd. conf:

1. Comment out the following three lines
# ServerAdmin
# ServerName
# DocumentRoot
2. Remove the comments of mod_proxy.so and mod_proxy_ajp.so.
3. # Virtual hosts
# Include conf/extra/httpd-vhosts.conf (find this line, remove the previous)
/Conf/extra/httpd-vhosts.conf

4. Open/conf/extra/httpd-vhosts.conf
#192.168.1.24 is the local Ip address
NameVirtualHost 192.168.1.24: 80

# Php Tutorial project
<VirtualHost 192.168.1.24: 80>

<Directory "D:/phproot/phpmyadmin">

DirectoryIndex index. php

</Directory>

ServerAdmin baibiao @ gmail.com

ServerName email.sinoepiboly.com

# ServerAlias email.sinoepiboly.com

DocumentRoot D:/phproot/phpmyadmin

</VirtualHost>

========================================================== ======================================

Method 2:

Multi-second-level domain name host development environment settings
Step 1: implement DNS resolution

Find the host file of the local machine, generally in C: WINNTsystem32driversetc, add at the end of the file:

127.0.0.1 localhost
127.0.0.1 www.com.cn
127.0.0.1 home.com.cn
127.0.0.1 mail.com.cn
127.0.0.1 music.com.cn
127.0.0.1 browseusers.com.cn
127.0.0.1 search.com.cn
127.0.0.1 invite.com.cn
127.0.0.1 rank.com.cn
127.0.0.1 blog.com.cn
127.0.0.1 favorites.com.cn
127.0.0.1 forum.com.cn
127.0.0.1 groups tutorial .com.cn
127.0.0.1 events.com.cn
127.0.0.1 classifieds.com.cn
127.0.0.1 signup.com.cn
192.168.6.153 I .com.cn
192.168.6.153 x.com.cn

Where
192.168.6.2 I .com.cn
192.168.6.2 x.com.cn
The technician does not make any changes, but is dedicated to the art page.

Step 2: Configure apache

Open httpd. conf. Take music.com.cn as an example. Add other columns as follows:

1. Guarantee
Listen 80

2. Open comments
NameVirtualHost *: 80

3. Add at the end
<VirtualHost *: 80>
ServerAdmin x_cn@msn.com
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/espace/music"
ServerName music.com.cn
</VirtualHost>
<VirtualHost *: 80>
ServerAdmin x_cn@msn.com
DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs/espace/blog"
ServerName blog.com.cn
</VirtualHost>

...

Restart. Apache virtual host settings are complete.


IP address-based virtual host configuration
Listen 80
DocumentRoot/www/example1
ServerName www.example1.com
DocumentRoot/www/example2
ServerName www.example2.org


IP-based and multi-port virtual host configuration
Listen 172.20.30.40: 80
Listen 172.000030.40: 8080
Listen 172.20.30.50: 80
Listen 172.20.30.50: 8080

DocumentRoot/www/example1-80
ServerName www.example1.com
DocumentRoot/www/example1-8080
ServerName www.example1.com
DocumentRoot/www/example2-80
ServerName www.example1.org
DocumentRoot/www/example2-8080
ServerName www.example2.org

Domain name-based VM configuration on a server with a single IP address:
# Ensure that Apache listens on port 80
Listen 80
# Listen for virtual host requests on all IP addresses
NameVirtualHost *: 80
DocumentRoot/www/example1
ServerName www.example1.com
ServerAlias example1.com. * .example1.com
# Other directives here
DocumentRoot/www/example2
ServerName www.example2.org
# Other directives here

Configure a domain name-based VM on a server with multiple IP addresses:
Listen 80
# This is the "main" server running on 172.20.30.40
ServerName server.domain.com
DocumentRoot/www/mainserver
# This is the other address
NameVirtualHost 172.20.30.50
DocumentRoot/www/example1
ServerName www.example1.com
# Other directives here...
DocumentRoot/www/example2
ServerName www.example2.org
# Other directives here...

Run different sites on different ports:
Configure a domain name-based virtual host on a multi-port server.
Listen 80
Listen 8080.
NameVirtualHost 172.20.30.40: 80
NameVirtualHost 172.000030.40: 8080
ServerName www.example1.com
DocumentRoot/www/domain-80
ServerName www.example1.com
DocumentRoot/www/domain-8080
ServerName www.example2.org
DocumentRoot/www/otherdomain-80
ServerName www.example2.org
DocumentRoot/www/otherdomain-8080

Configuration of domain name-based and IP-based hybrid virtual hosts:
Listen 80
NameVirtualHost 172.20.30.40
DocumentRoot/www/example1
ServerName www.example1.com
DocumentRoot/www/example2
ServerName www.example2.org
DocumentRoot/www/example3
ServerName www.example3.net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.