菜单
本页目录

第 7 次课 Web服务器配置

一,概述

-万维网三要素:http、html、url
-http协议:超文本传输协议,规定了浏览器和万维网服务器之间互相通信的规则
-html:超文本标记语言,规定了网页的标签
-url:统一资源定位符,规定了资源在互联网中的地址

1.1 Web

-web服务器:接收客户端的请求,将请求的资源返回给客户端
  动态两种架构:
    LAMP:linux+apache+mysql+php
        L:linux操作系统
        A:apache服务器
        M:mysql数据库
        P:php解释器(编程语言)
    全套微软:
        Windows服务器:
        IIS:服务器
        MSSQL:数据库
        ASP:编程语言

1.2 apache服务器安装

rpm -qa|grep httpd           //查看是否安装了apache服务器
    httpd-tools-2.4.6-88.el7.centos.x86_64    //工具包
    httpd-2.4.6-88.el7.centos.x86_64          //服务包
    httpd-devel-2.4.6-88.el7.centos.x86_64   //开发包

yum -y install httpd         //安装apache服务器
systemctl start httpd          //启动apache服务器

1.3 apache相关目录与配置文件

-配置文件:/etc/httpd/conf/httpd.conf

-主配置文件:/etc/httpd/conf/httpd.conf

-虚拟主机配置文件目录:/etc/httpd/conf.d/      //这是目录,里面存放附加配置文件
-conf.d目录中,所有的.conf文件,全部包含进主配置文件,用户可以在不修改主配置文件的情况下,通过修改conf.d目录中的配置文件,来达到配置虚拟主机的目的。

-日志文件:/var/log/httpd/access_log

-网站发布默认文档根目录:/var/www/html/    

1.4 配置文件详解:

1、global                          //全局配置
        serverRoot                        //服务器根目录
        listen                            //监听端口
        pidFile                           //进程号文件
        user                              //运行用户
        group                             //运行组
        serverAdmin                       //管理员邮箱
        serverName                        //主机名
        <   目录>                         //目录访问控制
2、main server                     //主服务配置
        DocumentRoot                      //网站文档根目录
        DirectoryIndex                    //首页名称
        AddDefaultCharset                  //编码格式

3、virtual host                    //虚拟主机配置

2 配置需要更改的文件

cd /home/wangxin/public_html/      //在这个文件路径中存放.html文件以及辅助文件,如.css .js等

vim XX.html    //编辑这个文件

[root@localhost ~]# vim /etc/named.conf                     //这里编辑dns服务
更改三个“any”

[root@localhost ~]# vim /etc/named.rfc1912.zones            //dns服务编辑
zone "wangxin.jw4b.com" IN {
        type master;
        file "wangxin.com.zone";      //域名反向解析的文件名,通常在  /var/named/当中,其创建过程为:cp named.localhost  wangxin.com.zone//
        allow-update { none; };   
};
编辑如上的域名,以便使用域名访问web个人网页  上图为“www.wangxin.jw4b.com"

3 配置httpd服务过程


1,更改网卡设置 2,systemctl stop firewalld.service //关闭防火墙

2,cd /home/wenjianm/zhiwenjianming/htmlwenjian.html或/var/www/html/wenjian.html wenjianming.html //进入这个文件可进行网页内容的撰写

3,vim /etc/httpd/conf/httpd.conf //编辑主配置文件

4,systemctl restart httpd.service //重启httpd服务


[root@localhost ~]# mkdir /var/web1
[root@localhost ~]# mkdir /var/web2
[root@localhost ~]# echo "this is my web of host 192.168.1.1">> /var/web1/index.html
[root@localhost ~]# vim /var/web2/index.html
[root@localhost ~]# chmod -R 777 /var/web1
[root@localhost ~]# chmod 777 /var/web1/index.html 
[root@localhost ~]# chmod -R 777 /var/web2
[root@localhost ~]# chmod 777 /var/web2/index.html 
[root@localhost ~]# mkdir -p /var/log/httpd/www.web1.com 
[root@localhost ~]# mkdir -p /var/log/httpd/www.web2.com 
[root@localhost ~]# touch /var/log/httpd/www.web1.com/error.log
[root@localhost ~]# touch /var/log/httpd/www.web2.com/error.log
[root@localhost ~]# vim /etc/httpd/conf.d/ipvh.conf
            --------------------------------------
            <VirtualHost 192.168.1.1>
            ServerAdmin webmaster@web1.com
            DocumentRoot /var/web1
            ServerName www.web1.com
            ErrorLog /var/log/httpd/www.web1.com/error.log
            </virtualHost>
            <VirtualHost 192.168.1.2>
            ServerAdmin webmaster@web2.com
            DocumentRoot /var/web2
            ServerName www.web2.com
            ErrorLog /var/log/httpd/www.web2.com/error.log
            </virtualHost>

            --------------------------------------

[root@localhost ~]# vim  /etc/selinux/config     //并不是每一个都要改,但还是建议用cat命令检查一下
            --------------------------------------
            SELINUX=disabled      //此处为更改过后的样式,更改完成后需要重启服务器。shutdown -r now
            --------------------------------------
[root@localhost ~]# systemctl restart httpd
[root@localhost ~]# vim /etc/httpd/conf/httpd.conf
            ------------------------------------------
            ServerName 192.168.1.1

            <Directory />
                AllowOverride none
                # Require all denied
            </Directory>
            ------------------------------------------

[root@localhost ~]# systemctl restart httpd

承接上面的操作,接着:


 nmtui
[root@localhost ~]# systemctl restart network
[root@localhost ~]# vim /etc/named.conf
[root@localhost ~]# vim /etc/named.rfc1912.zones
[root@localhost ~]# cd /var/named/
[root@localhost named]# cp named.localhost b.com.zone
[root@localhost named]# vim b.com.zone 
        -------------------------------------------
        $TTL 1D
		@	IN SOA	b.com. root.b.com. (
							0	; serial
							1D	; refresh
							1H	; retry
							1W	; expire
							3H )	; minimum
		@ IN NS dns.b.com.
	    dns IN A 192.168.1.1
		www IN A 192.168.1.1
        -------------------------------------------

[root@localhost named]# cp named.localhos s.com.zone
[root@localhost named]# vim s.com.zone 
        -------------------------------------------
        $TTL 1D
		@	IN SOA	s.com. root.s.com. (
					0	; serial
					1D	; refresh
					1H	; retry
					1W	; expire
					3H )	; minimum
		@ IN NS dns.s.com.
		dns IN A 192.168.1.1
		www IN A 192.168.1.1
        -------------------------------------------

[root@localhost named]# chown root:named s.com.zone         
[root@localhost named]# chown root:named b.com.zone 
[root@localhost named]# mkdir -p /var/webs/s
[root@localhost named]# mkdir -p /var/webs/b
[root@localhost named]# echo "Welcom to www.a.com">>/var/webs/a/index.html
[root@localhost named]# echo "Welcom to www.c.com">>/var/webs/c/index.html
[root@localhost named]# chmod -R 777 /var/webs/s
[root@localhost named]# chmod -R 777 /var/webs/b
[root@localhost named]# chmod  777 /var/webs/b/index.html 
[root@localhost named]# chmod  777 /var/webs/s/index.html   
[root@localhost named]# vim /etc/httpd/conf.d/ymvh.conf
		--------------------------------------------------
        <VirtualHost 192.168.1.1>
		ServerAdmin webmaster@s.com
    		DocumentRoot /var/webs/s
    		ServerName www.s.com
    		directoryindex index.html
		</VirtualHost>
		<VirtualHost 192.168.1.1>
    		ServerAdmin webmaster@b.com
    		DocumentRoot /var/webs/b
    		ServerName www.b.com
    		directoryindex index.html
		</VirtualHost>
		--------------------------------------------------
[root@localhost named]# systemctl restart httpd
[root@localhost named]# systemctl restart named