小型网络中心服务器配置(四)WWW服务器的安装与配置
小型网络中心服务器配置(四)WWW服务器的安装与配置
为做好模拟总公司及分公司网站的建设,网络中心经过研究,拟建立一台www服务器,存放公司总站网站、各分公司网站,维护和更新则由各自分公司自己进行,具体描述如下:
- 公司的主网站为www. wmmtest. edu. en, IP地址为192. 168. 217.157,对外访问端口为80。
- 各分公司网站分别为hb. wmmtest. edu. cn、 gd. wmmtest. edu.cn等,IP都为192. 168.217.157对外端口为8000 ~ 8080.
- 将用户wmm及wmmtest设置为认证用户,并将认证用户的口令改为123456。
- /var/www/html/file/目录中的所有网页文件只允许认证用户wmm和wmmtest访问。
- /var/www/html/file/目录中的所有网页文件只允许IP地址处在192.168.217.*网段的计算机访问。
- 利用虚拟机在服务器上架设公司网站及各分公司网站。
下面先看下实施流程:
1、Apache服务器分析
① WWW服务器与Apache服务器软件
Internet中最热门的服务是WWW服务,也称Web服务。WWW服务系统采用客户机/服务器工作模式,都遵循HTTP协议,默认采用80端口进行通信。客户机与服务器之间的工作模式如图所示:
WWW服务器负责管理Web站点的管理与发布,通常使用Apache服务器软件。WWW客户机利用Internet Explorer、Firefox 等网页浏览器查看网页。
Linux凭借其高稳定性成为架设www服务器的首选,而基于Linux架设www服务器时通常采用Apache软件。Apache可运行与UNix、Linux等平台,功能强大,技术成熟,自有,开放。
② 服务器的软件包
postgresql-libs: postgresql类库。
apr: Apache运行环境类库。
apr-util: Apache运行环境工具类库。
httpd:Apache服务器软件。
③ Apache服务器相关配置文件
Apache服务器的所有配置信息都保存在/etc/ htpd/ conf/httpd. conf 文件中,根据Apache服务器的默认设置,Web 站点的相关文件保存在/var/www目录,Web 站点的日志文件保存在/var/log/httpd目录。
与Apache服务器和Web站点相关的目录及文件如表所示:
文件/目录名 | 说明 |
---|---|
/ etc/ httpd/ conf/ httpd. conf | Apache的配置文件 |
/var/log/ httpd/ access_ log | Apache的访问日志文件 |
/var/log/httpd error _log | Apache的错误日志文件 |
/ var/ www/ | 默认Web站点的根目录 |
/var/ www/html | 默认Web站点HTML文档的保存目录 |
/var/ www/cgi - bin | 默认Web站点CGI程序的保存目录 |
… htaccess | 基于目录的配置文件,包含其所在目录的访问控制和认证等参数,使得存放此.htaccess文件的目录只允许它规定的用户访问 |
2、安装WWW服务器
[root@wwwserver ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:f1:b9:82 brd ff:ff:ff:ff:ff:ffinet 192.168.217.157/24 brd 192.168.217.255 scope global dynamic eno16777736valid_lft 1748sec preferred_lft 1748secinet6 fe80::20c:29ff:fef1:b982/64 scope link valid_lft forever preferred_lft forever
[root@wwwserver ~]#
① 安装软件:
[root@wwwserver ~]# yum install -y httpd
② 配置WWW服务器
(1)设置认证用户:
用htpasswd命令依次设置wmm、wmmtest为认证用户,密码为123456,
[root@wwwserver ~]# htpasswd -c /var/www/usrpass wmm #-c参数是创建一个新文件
New password:
Re-type new password:
Adding password for user wmm
[root@wwwserver ~]# htpasswd /var/www/usrpass wmmtest
New password:
Re-type new password:
Adding password for user wmmtest
可以查看帮助文档:
[root@wwwserver ~]# htpasswd --help
Usage:htpasswd [-cimBdpsDv] [-C cost] passwordfile usernamehtpasswd -b[cmBdpsDv] [-C cost] passwordfile username passwordhtpasswd -n[imBdps] [-C cost] usernamehtpasswd -nb[mBdps] [-C cost] username password-c Create a new file.-n Don't update file; display results on stdout.-b Use the password from the command line rather than prompting for it.-i Read password from stdin without verification (for script usage).-m Force MD5 encryption of the password (default).-B Force bcrypt encryption of the password (very secure).-C Set the computing time used for the bcrypt algorithm(higher is more secure but slower, default: 5, valid: 4 to 31).-d Force CRYPT encryption of the password (8 chars max, insecure).-s Force SHA encryption of the password (insecure).-p Do not encrypt the password (plaintext, insecure).-D Delete the specified user.-v Verify password for the specified user.
On other systems than Windows and NetWare the '-p' flag will probably not work.
The SHA algorithm does not use a salt and is less secure than the MD5 algorithm.
[root@wwwserver ~]#
(2)设置/var/www/html/file目录中的所有网页文件只允许认证用户访问
①用mkdir命令在/var/www/html目录下新建file目录。
②创建或复制一个index. html文件,并放到/var/ www/html/file目录中。
[root@wwwserver file]# vi index.html
Welcome to linux
③用文本编辑器打开配置文件/etc/ httpd/ conf/httpd. conf
[root@wwwserver file]# vi /etc/httpd/conf/httpd.conf
………………………………
<Directory "/var/www/html/file">AllowOverride noneAuthName "share web"AuthType BasicAuthUserFile /var/www/usrpassrequire valid-user
</Directory>
④修改httpd. conf文件中“ServerName www. example. com:80” 为“ServerName localhost :80”。
[root@wwwserver file]# vi /etc/httpd/conf/httpd.conf
ServerName localhost:80
⑤命令重启httpd服务。
(3)创建. htacces文件,设置/var/ www html file 网页文件只允许特定网段访问
①用文本编辑器’创建var/ www/ html/file/. htaccess 文件
[root@wwwserver file]# pwd
/var/www/html/file
[root@wwwserver file]# touch .htaccess
[root@wwwserver file]# vi .htaccess
Order deny,all
Deny from all
Allow from 192.168.217.0/24
[root@wwwserver file]# ls -a
. .. .htaccess index.html
②用 systemctl restart httpd 命令重启httped 服务。
[root@wwwserver file]# systemctl restart httpd
[root@wwwserver file]# systemctl status httpd.service
● httpd.service - The Apache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)Active: active (running) since Mon 2019-10-14 18:38:08 EDT; 1s agoDocs: man:httpd(8)man:apachectl(8)Process: 3148 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=1/FAILURE)Main PID: 3161 (httpd)Status: "Processing requests..."CGroup: /system.slice/httpd.service├─3161 /usr/sbin/httpd -DFOREGROUND├─3162 /usr/sbin/httpd -DFOREGROUND├─3163 /usr/sbin/httpd -DFOREGROUND├─3164 /usr/sbin/httpd -DFOREGROUND├─3165 /usr/sbin/httpd -DFOREGROUND└─3166 /usr/sbin/httpd -DFOREGROUNDOct 14 18:38:08 wwwserver systemd[1]: Starting The Apache HTTP Server...
Oct 14 18:38:08 wwwserver systemd[1]: Started The Apache HTTP Server.
[root@wwwserver file]#
3、建立个人 Web站点
① 用文本编辑器打开配置文件htpd. conf,找到mod_ usedir. c模块并修改mod_userdir.c模块。
注意:
只需要修改UserDir disabled 注释掉
UserDir public_html 去掉注释
[root@wwwserver conf.d]# pwd
/etc/httpd/conf.d
[root@wwwserver conf.d]# ls
autoindex.conf README userdir.conf welcome.conf
[root@wwwserver conf.d]# vi userdir.conf
#
# UserDir: The name of the directory that is appended onto a user's home
# directory if a ~user request is received.
#
# The path to the end user account 'public_html' directory must be
# accessible to the webserver userid. This usually means that ~userid
# must have permissions of 711, ~userid/public_html must have permissions
# of 755, and documents contained therein must be world-readable.
# Otherwise, the client will only receive a "403 Forbidden" message.
#
<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:#UserDir public_html ############## 这里取消注释
</IfModule>
② 修改配置文件httpd. conf,设置用户个人Web站点的访问默认权限
(1)用文本编辑器打开配置文件httpd. conf,找到/home/ * public html 模块。去掉该模块配置内容中的所有“#”号。
[root@wwwserver ]# vi httpd.conf
(2)在最后一行加入“ServerName localhost: 80”语句
ServerName localhost:80
③在用户主目录中创建public_html子目录,并将相关网页保存其中。
①用mkdir在wmm、wmmtest、 whit 用户主目录中创建public_html 子目录。
[root@wwwserver conf]# mkdir /home/wmm/public_html
[root@wwwserver conf]# mkdir /home/wmmtest/public_html
[root@wwwserver conf]# mkdir /home/whit/public_html
②分别将主页文件index. html复制到用户的个人主目录下的public_htm子目录中。
[root@wwwserver conf]# cp /var/www/html/file/index.html /home/wmm/public_html/
[root@wwwserver conf]# cp /var/www/html/file/index.html /home/wmmtest/public_html/
[root@wwwserver conf]# cp /var/www/html/file/index.html /home/whit/public_html/
④ 修改用户主目录权限
(1)把/home/wmm 添加其他用户执行权限,修改其他两个用户的其他用户执行权限:
[root@wwwserver home]# ll
total 0
drwxr-xr-x. 3 root root 24 Oct 14 19:02 whit
drwxr-xr-x. 3 root root 24 Oct 14 19:02 wmm
drwxr-xr-x. 3 root root 24 Oct 14 19:02 wmmtest
[root@wwwserver home]# chmod o-x whit
[root@wwwserver home]# chmod o-x wmmtest/
[root@wwwserver home]# ll
total 0
drwxr-xr--. 3 root root 24 Oct 14 19:02 whit
drwxr-xr-x. 3 root root 24 Oct 14 19:02 wmm
drwxr-xr--. 3 root root 24 Oct 14 19:02 wmmtest
⑤ 重启httpd服务
[root@wwwserver conf]# systemctl restart httpd
4、建立虚拟主机
①在/var/www目录中分别建立vhost-ip1和vhost-ip2子目录。
[root@wwwserver conf]# mkdir /var/www/vhost-ip1
[root@wwwserver conf]# mkdir /var/www/vhost-ip2
[root@wwwserver conf]#
②分别在/var/www/vhost-ipl和/val/www/vhost-ip2目录中创建index.html文件。
[root@wwwserver conf]# echo "Welcome to ip1" > /var/www/vhost-ip1/index.html
[root@wwwserver conf]# echo "Welcome to ip2" > /var/www/vhost-ip2/index.html
③用文本编辑器打开配置文件httpd.conf以进行编辑。
假设一个分给芜湖 一个分给安徽
假设一个分给芜湖 一个分给安徽
Listen 8012
Listen 8008
<VirtualHost 192.168.217.157:8012>DocumentRoot /var/www/vhost-ip1ServerName whweb.wmmtest.edu.cn
</VirtualHost>
<VirtualHost 192.168.217.157:8008>DocumentRoot /var/www/vhost-ip2ServerName anweb.wmmtest.edu.cn
</VirtualHost>
5、防火墙配置
[root@wwwserver conf]# systemctl stop firewalld
[root@wwwserver conf]# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
[root@wwwserver conf]# [root@wwwserver conf]# setenforce 0
解释下
①httpd. conf文件格式有如下规则。
配置语句的语法形式为“参数名称参数值”。
配置语句中除了参数值以外,所有的选项都不区分大小写。
可使用“#”表示该行为注释信息。虽然配置语句可放置在文件的任何位置,但为方便管理,最好将配置语句放在其相应的部分。
通常在进行首次Apache服务器配置之前,都会先备份默认的httpd.conf,这样即使配置出错也能还原到初始状态。
② 全局环境
httpd. conf文件的全局环境( Section l: Global Environment) 部分的默认配置,基本能满足用户的需要,用户可能需要修改的全局参数如下。
(1) 相对根目录
相对根目录是Apache存放配置文件和日志文件的目录,默认为/etehttpd。此目录一般包含conf和logs子目录。配置语句如下:
ServerRoot“/etc/httpd"
DocumentRoot“/var/ www/ html
(2)响应时间
Web站点的响应时间以秒为单位,默认为120秒。
如果超过这段时间仍然没有传输任何数据,那么Apache服务器将断开与客户端的连接。
配置语句如下:
Timeout 120
(3)保持激活状态
默认不保持与Apache服务器的连接为激活状态,通常将其修改为on,即允许保持连接,以提高访问性能。配置语句如下:
KeepAlive off
(4)最大请求数
最大请求数是指每次连接可提出的最大请求数量,默认值为100,设置为0则没有限制。
配置语句如下:
MaxKeepAliveRequests 100
(5)保持激活的响应时间
允许保持连接时,可指定连续两次连接的间隔时间,如果超出设置值,则被认为连接中断,默认值为15秒。
配置语句如下:
KeepAliveTimeout 15
(6)监听端口
Apache服务器默认会在本机的所有可用IP地b上的TCP80端口监听客户端的请求。
配置语句如下:
Listen 80
③ 主服务器配置
httpd. conf配置文件的主服务器配置( Section2: Main server configuration) 部分设置默认Web站点的属性,其中可能需要修改的参数如下:
(1)管理员地址
当客户端访问Apache服务器发生错误时,服务器会向客户端返回错误提示信息。
其中,通常包括管理员的E - mail地址。
默认的E - mail地址为root@主机名,应正确设置此项。
配置语句如下:
ServerAdmin root@ rhel
(2)服务器名
为方便识别服务器自身的信息,可使用ServerName语句来设置服务器的主机名称。
如果此服务器有域名,则输人域名,否则输入服务器的IP地址。
配置语句如下:
ServerNamewww. example. com
(3)主目录
Apache服务器的主目录默认为/var/ www html,也可根据需要灵活设置。
配置语句如下:
DocumentRoot“/var/ www/ html"
④ 默认文档
默认文档是指在Web浏览器中仪输人web站点的城名或IP地址就显示的网页。
按照hupd conf文件的默认设置,访问Apche服务器时如果不指定网页名称,Apche 服务器将显示指定目录下的index. html或idex hml. var 文件。
配置语可如下:
DirectoryIndex index.html index.html.var
用户可根据实际需要对DirectoryIndex 语句进行修改,如果有多个文件名,则各文件名之间用空格分隔。Apache服务器根据文件名的先后顺序查找指定的文件名。
如果能找到第1个则调用,否则可查找并调用第2个,以此类推。
实际上,Apache 服务器的功能十分强大,可实现访问控制、认证、用户个人站点、虚拟主机等功能。
根据www服务器的实际情况修改htptd. conf文件中的部分参数,重启httpd守护进程,并将包括index. html在内的相关文件复制到指定的Web站点根目录(默认为/var/www/html),就能架设起一个简单的www服务器。
小型网络中心服务器配置(四)WWW服务器的安装与配置相关推荐
- 2016终端服务器配置,2016服务器的安装与配置.ppt
2016服务器的安装与配置 Chapter Web服务器的安装与配置 实验目标 了解IIS包含的主要服务 安装Web服务 掌握配置默认网站 掌握配置虚拟目录 掌握新建网站 掌握配置主机头 WWW服务 ...
- Linux NFS服务器的安装与配置
2019独角兽企业重金招聘Python工程师标准>>> 一.NFS服务简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由 ...
- redis 服务器/客户端安装与配置
redis 服务器/客户端安装与配置 1 redis server 1.1 获取redis源码包 //官网 http://redis.io/ wget -c http://redis.googleco ...
- Lotus Sametime 服务器的安装和配置
IBM Lotus Sametime 是一款强大的实时协作软件,目前最新版本是 7.5.1.通过它,您不仅能够进行网络聊天,而且可以方便地召开网络会议.在网络社区中与其他人进行沟通.了解更多关于 Lo ...
- CentOS 6.3下rsync服务器的安装与配置[转]
CentOS 6.3下rsync服务器的安装与配置 一.rsync 简介 Rsync(remote synchronize)是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件,也可以 ...
- Linux NFS服务器的安装与配置(最简单的文件共享集群)
一.NFS服务简介 NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操 ...
- 虚拟服务器数据库安装与配置,虚拟服务器数据库安装与配置
虚拟服务器数据库安装与配置 内容精选 换一换 WordPress是使用PHP语言开发的博客平台,用户可以在支持PHP和MySQL数据库的服务器上搭建属于自己的网站,本文教您通过华为云虚拟私有云.弹性云 ...
- Nginx服务器上安装并配置PHPMyAdmin的教程
这篇文章主要介绍了Nginx服务器上安装并配置PHPMyAdmin的教程,附带一条PHPMyAdmin加载慢的解决方法:)需要的朋友可以参考下 一. 准备工作: 如果mysql的root账号为空,需要 ...
- citrix创建虚拟机服务器,在 ESXi 服务器上安装并配置 Citrix SD-WAN Center
在 ESXi 服务器上安装并配置 Citrix SD-WAN Center April 13, 2021 贡献者: C 安装 VMware vSphere 客户端 以下是下载和安装用于创建和部署 Ci ...
最新文章
- Spring Boot中验证码实现kaptcha
- python随机森林特征重要性_Python中随机森林回归的特征重要性
- 2-算法 矩阵 数组类
- 网络管理中的安全保障
- 1. C++基础知识学习及其深入理解(面向对象部分还没学) -- 课程1完成
- cesium-事件监听(获取点击位置的经纬度和高度)
- w ndows7旗舰版镜像下载,win7旗舰版32位原版iso
- 为什么宿醉那么缺水_坚决应对云的宿醉
- 内存屏障(Memory Barrier)(一)什么是写屏障?
- Android程序员二本出身,阿里架构师经验分享
- 浅谈RESTful风格
- 内存管理器(十)kernel内存管理----数据结构
- 论劳动者的休息权及其法律保障
- Android 极光推送SDK集成
- 数据收集整理(长期更新)
- 三花集金花茶“茶族皇后”不仅貌美,还有丰富的营养价值
- 牛油刀ButterKnife的使用
- android省电开发之cpu降频
- 编写图片复制JAVA代码_何编写[java]代码为图片赋予“铅笔素描”效果
- matlab 开放,基于MATLAB的小区开放对道路通行影响的研究