. apache2 setting up multiple virtual domain names

Source: Internet
Author: User
Tags phpmyadmin

<virtualhost 127.0.0.2:80>    ServerName www.xylilun.cn    documentroot e:/www/ylll  <directory e:/ www/ylll>        allowoverride allorder allow,denyallow from all    </Directory></VirtualHost>

  

Http://randomclan.blog.163.com/blog/static/1453009820128249542381/apache2 setting up multiple virtual domain names

2012-09-24 09:54:23|  Category: The world of yards farming | Tags: apache | font size Big Small subscription

In general, we use localhost to access the server on this computer, and in our c:/windows/system32/drivers/etc/hosts file, there is a default:
127.0.0.1 localhost

When we type in the browser address bar:
http://localhost

, you will see many folders in the root directory of the server (if your root directory is not a single site), like this:
Index of/

* bak/
* b_discuz/
* b_supesite/
* b_ucenter/
* b_uchome/
* b_uchome_bak/
* b_xspace/
* discuz_x1/
* javascript/
* newuch/
* php/
* uchutf8/
* Zend framework_1.10.8/
* zendphpweb20/
* mycms/
* phpmyadmin/
* useradminmanager/

Now I want to access sites in my root directory through a custom "domain name," such as:

1, the root directory has a phpmyadmin/folder (the penultimate), it is a web-version of the database management system (certainly not unfamiliar with it!). ), I would like to access a simple:
Http://dbmanager

To enter the system (without entering localhost, then clicking phpmyadmin/);

2, the root directory has a zendphpweb20/folder (the third last), it is just a local application site, I want to access by:
Http://phpweb20

To enter this local site;

What do you want to do now? Come with me! See below:

1> Modify the system's Hosts file:

Open the previously mentioned system's hosts file, to add two "fake" DNS entries to our computer, adding code:
127.0.0.2 Dbmanager
127.0.0.3 Phpweb20

In this way, our browser resolves the dbmanager hostname to 127.0.0.2 and resolves the phpweb20 hostname to 127.0.0.3.

2> Modifying the Apache configuration file:

In my native Apache, the master profile is in:
D:/usr/local/apache2/conf/httpd.conf

Said to modify the Apache configuration file, actually just added some content, because do not want to modify the Apache master configuration file, so we'd better write their own virtual host configuration sub-files at each site, and then use the include directive to include it in the Apache master configuration file.

In fact, at the bottom of the Apache main configuration file, there is a virtual host configuration example, but all are commented out:
# Example of a name-based virtual host:

#<virtualhost 127.0.0.2:80>
# ServerAdmin [email protected]
# DocumentRoot D:\usr\webroot\webhosting1
# ServerName 127.0.0.2
# errorlog Logs/dummy-host.example.com-error_log
# Customlog Logs/dummy-host.example.com-access_log Common
#</virtualhost>

#<virtualhost 127.0.0.3:80>
# ServerAdmin [email protected]
# DocumentRoot D:\usr\webroot\webhosting2
# ServerName 127.0.0.3
# errorlog Logs/dummy-host.example.com-error_log
# Customlog Logs/dummy-host.example.com-access_log Common
#</virtualhost>

#<virtualhost 127.0.0.4:80>
# ServerAdmin [email protected]
# DocumentRoot D:\usr\webroot\webhosting3
# ServerName 127.0.0.4
# errorlog Logs/dummy-host.example.com-error_log
# Customlog Logs/dummy-host.example.com-access_log Common
#</virtualhost>

Add code at the bottom of the configuration file:
# contains Dbmanager virtual host configuration file
Include d:/usr/webroot/phpmyadmin/httpd.conf

# contains PHPWEB20 virtual host configuration file
Include d:/usr/webroot/zendphpweb20/httpd.conf

(The root directory of my localhost is d:/usr/webroot/)

3> Create sub-profiles for each virtual host:

Create a Dbmanager profile: d:/usr/webroot/phpmyadmin/httpd.conf
#dbmanager Virtual Host Settings
<virtualhost 127.0.0.2:80>
ServerName Dbmanager
DocumentRoot D:/usr/webroot/phpmyadmin

<directory d:/usr/webroot/phpmyadmin>
AllowOverride All
Options All
</Directory>
</VirtualHost>

Create a PHPWEB20 profile: d:/usr/webroot/zendphpweb20/httpd.conf
#phpweb20 Virtual Host Settings
<virtualhost 127.0.0.3:80>
ServerName Phpweb20
DocumentRoot D:/usr/webroot/zendphpweb20/htdocs

<directory d:/usr/webroot/zendphpweb20/htdocs>
AllowOverride All
Options All
</Directory>

#修改 PHP configuration (optional)
Php_value include_path.;D:/ Usr/webroot/zendphpweb20/include;d:/usr/local/php5/pear
Php_value MAGIC_QUOTES_GPC off
Php_value register_globals off
</VirtualHost>

The configuration of each virtual host depends on the application site needs, documentroot for its root directory (Php_value is to modify the PHP operating parameters of this site, according to their own application needs to write, so you do not have to modify the PHP master configuration file).

4> Restart Apache Service:

That's not much to say.

Complete! OK, enter the input separately in the browser address bar:
Http://dbmanager
Http://phpweb20

Our aim is achieved!!

. apache2 setting up multiple virtual domain names

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.