HTTPD build Virtual host and Apache website basic Service

Source: Internet
Author: User
Tags hosting web hosting

Preface
  1. About Apache
  2. The main features of Apache
  3. Basic configuration of the HTTPD server
  4. Build httpd Virtual Host
About Apache:

Apache HTTP Server is a representative of open source software projects and is the world's first Web server software to use. It can run on almost all of the widely used computer platforms.
Because it is free open source software, there are always people to develop new features, new features, and modify the original flaws.

The main features of Apache:
    • > Open Source code: This is one of its important features, but also the basis for other features
    • > Cross-Platform Applications: Apache servers can run on most platforms
    • Supports a variety of Web programming languages: The Apache server can support Web programming languages including Perl, PHP, Python, Java, and so on.

    • > Modular Design: Apache does not centralize all of its functions within a single service program, but rather uses standard modules to achieve proprietary functionality.
    • > Very stable: Apache servers can be used to build Web sites with heavy load traffic
    • > Good security: Apache server has relatively good security, which is the common features of open source software
Basic configuration of the HTTPD server

1 • Install httpd service

Yum Install Httpd-y

2 • Modify the master configuration file

Vim/etc/httpd/conf/httpd.conf//HTTPD's master configuration file
The contents of the amendment are as follows:
Listen 192.168.100.20:80//Listening address
#Listen 80//need to comment out the IPV6 port
Service iptables stop//firewall off
Setenforce 0
Service httpd start//Open HTTPd Services

3 · Verify httpd:

Access listening Address: 192.168.100.20

4 • Modify Site content:

cd/var/www/html/
echo "This is Test Web" > index.html #在站点中写入测试的语句

To verify once again:

HTTPD build Multi-site (virtual host)

1 · You need to create a configuration file for the virtual host:

cd/etc/httpd/conf.d/
Vim vdir.conf #手动建立一个虚拟主机的配置文件
To add a configuration file format for a virtual directory:
Alias/test "/opt/test/" #别名,/test =/opt/test (site storage) add test when visiting the website
<directory "/opt/test/" > #开头定义路径 fixed format
Options Indexes multiviews followsymlinks #建立索引, fixed format
allowoverride None #不允许重写 (fixed format)
AuthName "Hello" #hello信息
AuthType Basic #认证类型 Basic is one of the most fundamental certifications
Authuserfile/etc/httpd/user #身份验证登陆 and specify the file seat
#authgroupfile/etc/httpd/group #组身份验证登陆和指定文件位子
#require Valid-user #开启用户认证
#require User Test #仅允许那些用户登陆
#Require Group Admin #仅允许那些组登陆
</Directory>

2 · We have written the configuration file, we need to establish a site now, because in the configuration file we specify the site is not, so we need to manually establish, and then the site to write data, easy to test!

Mkdir/opt/test #建立虚拟主机站点
echo "This is Test 2" >/opt/test/index.html #在站点中写入数据
Service httpd Restart #重启服务

Verify: This allows you to leverage the performance of the server

3 · We can also do access control lists, requiring user authentication configuration:

Htpasswd-c/etc/httpd/user Zhangsan
Vim/etc/httpd/conf.d/vdir.conf
Remove the following comments:
Require Valid-user #开启用户认证
Service httpd Restar #重启服务

Verify:

Virtual hosts based on different domain names

1 · When the number of virtual web hosts is large, it is recommended to use a separate virtual host profile and then load these configurations in httpd.conf files with include, which makes it easier to configure content maintenance. This creates a two-hostname configuration file as a column.

cd/etc/httpd/conf.d/
Vim host.conf #建立独立的主机名配置文件
Add the following configuration:
Namevirtualhost 192.168.100.20:80 #定义IP地址和端口
<virtualhost 192.168.100.20:80> #再次定义 (fixed format)
ServerAdmin [email protected] #管理员邮箱
Documentroot/opt/benet #定义站点目录
ServerName www.benet.com #服务器名字
Errorlog Logs/benet.com-error_log #错误日志文件名
Customlog Logs/benet.com-access_log Common #访问日子文件名
</VirtualHost>

Namevirtualhost 192.168.100.20:80 #定义IP地址和端口
<virtualhost 192.168.100.20:80> #再次定义 (fixed format)
ServerAdmin [email protected] #管理员邮箱
Documentroot/opt/baidu #定义站点目录
ServerName www.baidu.com #服务器名字
Errorlog Logs/baidu.com-error_log #错误日志文件名
Customlog Logs/baidu.com-access_log Common #访问日子文件名
</VirtualHost>

2 · The site directory written in the configuration file is not, so you need to create it manually, write some data at the site for easy testing

Mkdir/opt/benet
Mkdir/opt/baidu
echo "This is Benet" >/opt/benet/index.html
echo "This is Baidu" >/opt/baidu/index.html

3 · Since it is based on different domain names, we will build a DNS service:

rpm-ivh/mnt/packages/bind-9.8.2-0.17.rc1.el6_4.6.x86_64.rpm
Vim/etc/named.conf #修改主配置文件
The contents of the amendment are as follows:
Options {
Listen-on Port: (any;};
Listen-on-v6 Port 53 {:: 1;};
Directory "/var/named";
Dump-file "/var/named/data/cache_dump.db";
Statistics-file "/var/named/data/named_stats.txt";
Memstatistics-file "/var/named/data/named_mem_stats.txt";
allow-query {any;};
recursion Yes;

To modify a zone configuration file:

Vim/etc/named.rfc1912.zones
The contents of the amendment are as follows:
Zone "Benet.com" in {
Type master;
File "Benet.com.zone";
allow-update {none;};
};
Zone "Baidu.com" in {
Type master;
File "Baidu.com.zone";
allow-update {none;};
};

To modify a zone data configuration file:

cd/var/named/
Cp-p Named.localhost Benet.com.zone
Cp-p Named.localhost Baidu.com.zone
Vim Bent.com.zone
The contents of the amendment are as follows:
$TTL 1D
@ in SOA @ Admin. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS @
A 127.0.0.1
www in A 192.168.100.20

Modify the zone data file for the second domain name:

Vim Baidu.com.zone

$TTL 1D
@ in SOA @ Admin. (
0; Serial
1D; Refresh
1H; Retry
1W; Expire
3H); Minimum
NS @
A 127.0.0.1
www in A 192.168.100.20

Restart the service to begin verification:

Service httpd Restart
Service named restart


same IP different port access:

In vim/etc/httpd/conf/httpd.conf
Add as content:
Listen 192.168.100.20:8080

To add data to the vim/etc/httpd/conf.d/host.conf configuration file:
Add content as follows:

Namevirtualhost 192.168.100.20:8080
<virtualhost 192.168.100.20:8080>
ServerAdmin [email protected]
Documentroot/opt/accp01
ServerName www.accp.com
Errorlog Logs/accp.com-error_log
Customlog Logs/accp.com-access_log Common
</VirtualHost>

Establish a site and write data

Mkdir/opt/accp
echo "This is ACCP" >/opt/accp/index.html
Restart the service to verify that:

Experimental success!

Summarize:

The httpd server's master profile is httpd.conf, and other profiles can be loaded with the Include configuration item
HTTPD Services Support virtual Web hosting (build multi-site), can be based on domain name, port to access

HTTPd build Virtual Hosting and Apache Web Base services

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.