Lamp architecture-Set the default host for httpd (server multi-site run settings)

Source: Internet
Author: User

Default virtual host for httpd

One server can access multiple, each Web site is a virtual host;
A httpd service under the running of multiple websites, multiple domain names;
Note: any domain name resolves to this machine, can access the virtual host is the default virtual host, its own machine running site, except;

The DNS or Hosts file defines 192.168.188.2 as www.szl.com www.shu.com www.111.com;
The machine only runs two websites, szl.com and 111.com, and does not run www.shu.com;
When the default virtual host option is turned on, then using www.shu.com will jump directly to the default virtual host, which is the first host site of httpd-vhosts.conf;
Here the first site is szl.com, then www.shu.com will show www.szl.com site content;

Turn on the default virtual host option
vim /usr/local/apache2.4/conf/httpd.conf搜索httpd-vhosts取消注释Include conf/extra/httpd-vhosts.conf
Modify the web host site content
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf

Modify Content

<VirtualHost *:80>    DocumentRoot "/data/wwwroot/szl.com"    ServerName szl.com    ServerAlias www.szl.com    ErrorLog "logs/szl.com-error_log"    CustomLog "logs/szl.com-access_log" common</VirtualHost><VirtualHost *:80>    DocumentRoot "/data/wwwroot/111.com"    ServerName 111.com    ServerAlias www.example.com    ErrorLog "logs/111.com-error_log"    CustomLog "logs/111.com-access_log" common</VirtualHost>

Note: Here are the two Web site parameters, the first is the default virtual host;

Create two sites szl.com with 111.com
mkdir /data/wwwroot/mkdir /data/wwwroot/szl.commkdir /data/wwwroot/111.comvim /data/wwwroot/szl.comvim /data/wwwroot/111.com
在szl.com文件中输入php页面测试代码<?phpecho “szl.com”?>在111.com文件中输入php页面测试代码<?phpecho “111.com”?>
Error detection and update Apache configuration
/usr/local/apache2.4/bin/apachectl -t/usr/local/apache2.4/bin/apachectl graceful
Test results:

Browser input www.shu.com display content for the www.szl.com site;

Content comments

Virtual Host Content Comments:

DocumentRoot: Represents the site file path
ServerName: Representative website name;
Serveralias: website alias;
Errorlog: Error log path
Customlog: Log Path

Lamp architecture-Set the default host for httpd (server multi-site run settings)

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.