部署web服务

1.1 web服务简介

www 是环球信息网 的简写 ,中文名万维网,环球网,常简称为web。

web服务器,又称www服务器,主要利用应用层提供的HTTP协议,html文档格式。

1.2LAMP模型

LAMP网站架构是前国际流行的web框架

1.3项目实施

1.3.1安装Apache服务

[root@localhost ~]# yum install httpd
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
rhel7.6                                                                                                    | 3.6 kB  00:00:00     
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-95.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-95.el7.centos,它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要
--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要
--> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要
--> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要
--> 正在检查事务
---> 软件包 apr.x86_64.0.1.4.8-7.el7 将被 安装
---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装
---> 软件包 httpd-tools.x86_64.0.2.4.6-95.el7.centos 将被 安装
---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

==================================================================================================================================
 Package                        架构                      版本                                   源                          大小
==================================================================================================================================
正在安装:
 httpd                          x86_64                    2.4.6-95.el7.centos                    rhel7.6                    2.7 M
为依赖而安装:
 apr                            x86_64                    1.4.8-7.el7                            rhel7.6                    104 k
 apr-util                       x86_64                    1.5.2-6.el7                            rhel7.6                     92 k
 httpd-tools                    x86_64                    2.4.6-95.el7.centos                    rhel7.6                     93 k
 mailcap                        noarch                    2.1.41-2.el7                           rhel7.6                     31 k

事务概要
==================================================================================================================================
安装  1 软件包 (+4 依赖软件包)

总下载量:3.0 M
安装大小:10 M
Is this ok [y/d/N]: y
Downloading packages:
----------------------------------------------------------------------------------------------------------------------------------
总计                                                                                              240 MB/s | 3.0 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : apr-1.4.8-7.el7.x86_64                                                                                        1/5 
  正在安装    : apr-util-1.5.2-6.el7.x86_64                                                                                   2/5 
  正在安装    : httpd-tools-2.4.6-95.el7.centos.x86_64                                                                        3/5 
  正在安装    : mailcap-2.1.41-2.el7.noarch                                                                                   4/5 
  正在安装    : httpd-2.4.6-95.el7.centos.x86_64                                                                              5/5 
  验证中      : httpd-tools-2.4.6-95.el7.centos.x86_64                                                                        1/5 
  验证中      : mailcap-2.1.41-2.el7.noarch                                                                                   2/5 
  验证中      : apr-1.4.8-7.el7.x86_64                                                                                        3/5 
  验证中      : httpd-2.4.6-95.el7.centos.x86_64                                                                              4/5 
  验证中      : apr-util-1.5.2-6.el7.x86_64                                                                                   5/5 

已安装:
  httpd.x86_64 0:2.4.6-95.el7.centos                                                                                              

作为依赖被安装:
  apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-95.el7.centos mailcap.noarch 0:2.1.41-2.el7

完毕!

1.3.2进行其他准备工作

配置web服务器IP为172.11.16.2xx ,关闭防火墙,设置系统安全机制为permissive。

[root@localhost ~]# systemctl stop firewalld 
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# vi /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permissive
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected.
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

[root@localhost ~]# setenforce 0
[root@localhost ~]# getenforce 
Permissive

1.3.3启动与停止apache服务

[root@localhost ~]# systemctl start httpd

启动apache后可在浏览器通过IP访问apache默认首页

1.3.4修改主配置文件httpd.conf

httpd.conf是apache最核心的配置文件,位于/etc/httpd/conf/目录下

1.3.4.1 全局环境变量配置


这一部分的指令将影响整个 Apache 服务嚣。
(1) ServerRoot:投置 Apache 的配置文件、错误文件和日志文件的存放目录,且该日系是整个目录树的根节点。在默认情况下根路径为/etchutpd,可根据需要进行修改。
(②) Listen:设置 Apache 服务监听的IP 和端口。一般在使用非80的端口时设置。
(③) LoadModule:设置动态加载模块。
(4) Include conf d/*.conf:将由 Serveroot 参数指定的目录中子目录 conf.d 中的*,conf文件包含进来,即将/etc/httpd/conf.d目录中的*.conf 文件包含进来。
(⑤) User:指定运行 Apache服务的用户名,默认为 apache。
(⑥ )Group:指定运行 Apache服务的组名,默认为 apache。
(⑦ )KeepAlive Of:设置是否允许在同一个连接上传输多个请求,取值为 onloff。
MaxKeepAliveRequests:设置一次连接可以进行的HTTP 请求的最大次数。如果将此值设置为0,将不限制请求的数目。

(8)MaxKeepAliveRequests:设置一次连接可以进行的http请求的最大次数,如果将此参数设置为0将不再限制请求次数。
(9) KeepAliveTimeout: 设置持续作用中服务器在两次请求之间等待的最大时间间隔,默认值是15秒。如果服务器已经完成了一次请求,但在超过了该指令设置的时间间隔后,还没有收到下一次请求,那么服务器就断开连接。

1.3.4.2 主服务器配置


(1) ServerAdmin:设置服务器管理员的电子邮箱地址。如果客户端在访问服务器时出班错误,就把错误信息返回给客户端的浏览器,以便 Web 用户和管理员取得联系。
(2) ServerName:服务器用于辨识自己的主机名和端口号。如果没有申请域名,使用
P地址就可以,主要用于创建转向 URL,默认情况下是不需要没置这个参数的。
(③) DocumentRoot:网站数据的存放目录,默认为/var/www/html。
(4) Directory 目录容器:Apache 服务器可以利用 Directory 容器设置对指定目录进行访问控制

<Directory/>
Allow Override none
Require all denied
</Directory"/var/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all grantde  #允许所有请求访问资源
</Directory>    设置Apache主服务器网页文件存放目录的访问权限


1.3.5配置用户个人主页

[root@localhost~]# vim /etc/httpd/conf.d/userdir.conf
<IfModule mod_userdir.c>
//
// UserDir is disabled by default since it can confirm the presence
// of a username on the system (depending on home directory
// permissions).
// UserDir disabled   #注释掉,就可以开启个人主页功能
// 
// To enable requests to /~user/ to serve the user's public_html
// directory,remove the "UserDir disabled" line above,and uncomment
// the following line instead:
//
UerDir public_html  #启用网站数据在家目录中的保存路径
</IfModule>
http://IP or FQDN/~username 访问系统用户username 的web站点

chmod 755 /home/username 

cd /home/username

mkdir public_html

echo "hello I am username">>index.html

重启HTTPd服务 

systemctl restart httpd

在浏览器导航框内输入

http://172.20.xx.xx/~username

访问hz个人主页

1.3.6 配置虚拟目录


①创建物理路径/var/www/test/
[root@localhost~]#mkdir -p/var/www/test
②创建虚拟目录中的默认首页文件
[root@localhost~]#cd/var/www/test
[root@localhost test} #echo "hello,this is virtual directory">>index.html
③修改http.conf文件
[root@localhost test] #chmod 755 index.heml
④修改httpd.conf文件
[roof@localhost test]#vim /etc/httpd/conf/httpd.conf
Alias /test/ "/var/www/test/"    #定义虚拟目录 “/test/”,物理路径为“/var、www/test/”
<Directory "/var/www/test/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Require all granted
</Directory.
⑤重启httpd服务
[root@localhost~]# systemctl   restart  httpd
 

1.3.7 配置虚拟主机

<VirtualHost*:80>
ServerAdmin webmaster@dummy-host.example .com
#指定虚拟主机管理员的电子邮箱地址
ServerName domain.com                         #指定虚拟主机名称和端口号
DocumentRoot"/home/www"                 #制定虚拟主机中网站数据的目录
DirectoryIndex index.html index.php      #指定虚拟主机的默认主页
ErrorLog logs/dummy-host.example.com-error_log
#指定虚拟主机的错误日志存放路径
CustomLog logs/dummy-host.example.com-acccess_Log common
#指定虚拟主机的访问日志存放路径
<Directory "/home/www">              #网站目录的访问权限
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值