Lamp-apache Virtual Host

Source: Internet
Author: User

multiple virtual hosts can be configured on an Apache server, enabling a single server to provide multi-site services, in fact, to access different directories on the same server. Apache Virtual Host Configuration has 3 methods: IP-based configuration, domain-based configuration, and port-based configuration. The following shows the domain-based virtual hosts.

1. Edit httpd.conf

[Email protected] ~]# vi/usr/local/apache2.4/conf/httpd.confinclude conf/extra/httpd-vhosts.conf # # Enable httpd-vhosts.conf

2. Edit httpd-vhosts.conf

[[Email protected] ~]# vi /usr/local/apache2.4/conf/extra/httpd-vhosts.conf<virtualhost  *:80>                       # #默认虚拟主机     DocumentRoot  "/data/www/abc.com"     # #网站根目录     ServerName abc.com                   # #主域名      serveralias  abc.net     # #域名别名      ErrorLog  "Logs/abc.com-error_log"             # #错误日志      CustomLog  "Logs/abc.com-access_log"  common   # #访问日志 </virtualhost ><VirtualHost *:80>    DocumentRoot  "/data/www/123.com"      servername 123.com    errorlog  "Logs/123.com-error_log"     CustomLog  "Logs/123.com-access_log"  common</VirtualHost>

3. Create Site Directory and files

[[email protected] ~]# mkdir/data/www[[email protected] ~]# mkdir/data/www/abc.com[[email protected] ~]# mkdir/data/www /123.com[[email protected] ~]# Cat/data/www/abc.com/index.php<?phpecho "abc.com";? >[[email protected] ~]# Cat/data/www/123.com/index.php<?phpecho "123.com";? >[[email protected] ~]# chmod 755/data/www/123.com/index.php[[email protected] ~]# chmod 755/data/www/abc.com/index . php

4. Reload the configuration

[Email protected] ~]#/usr/local/apache2.4/bin/apachectl-tsyntax ok[[email protected] ~]#/usr/local/apache2.4/bin/ Apachectl Graceful

5. Test the virtual host effect

[Email protected] ~]# curl-x192.168.137.100:80 123.com<! DOCTYPE HTML PUBLIC "-//ietf//dtd HTML 2.0//en" >

The test found no permissions, because the index.php file was previously authorized, so the location problem is httpd.conf.

[Email protected] ~]# vi/usr/local/apache2.4/conf/httpd.conf<directory/> allowoverride none# Require all den IED # #将该行注释掉 </directory>[[email protected] ~]#/usr/local/apache2.4/bin/apachectl Graceful # #重新加载配置 [[Email Protected] ~]# curl-x192.168.137.100:80 123.com123.com[[email protected] ~]# curl-x192.168.137.100:80 abc.com abc.c Om[[email protected] ~]# curl-x192.168.137.100:80 # #匹配别名主机 Abc.com[[email protected] ~]# curl-x192.168.137.100:80 ABCD . com # #采用默认虚拟主机abc. com


This article is from "a Man & A computer" blog, please be sure to keep this source http://juispan.blog.51cto.com/943137/1951872

Lamp-apache Virtual Host

Related Article

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.