Web网络服务一般指允许用户通过浏览器访问到互联网中各种资源的服务,Web网络服务是一种被动访问的服务程序,即只有接收到互联网中其他主机发出的请求后才会响应,最终用于提供服务的Web服务器会通过http(超文本传输协议)或https(安全超文本传输协议)把请求的内容传送给用户。
目前这样的web网络服务程序有IIS(Windows),Nginx(新起之秀)和Apache。接下来介绍Apache。
一、部署Apache
1、挂载系统镜像光盘,配置yum目录,这个在上一篇中已经进行说明,不再重复。上一篇
2、下载httpd
[root@redhat Desktop]# yum install httpd
。。。省略。。。
3、启动服务且设置开机自启
[root@redhat Desktop]# systemctl start httpd
[root@redhat Desktop]# systemctl enable httpd
ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'
4、查看是否部署成功
二:配置服务文件的参数
如下,httpd在linux系统中的配置文件及路径。
查看主配置文件
修改主页内容
已知网站目录存放路径为/var/www/html,在此目录下添加index.html文件,就可以修改主页信息,再打开127.0.0.1,会发现主页信息变为了自己刚写的index文件内容。
[root@redhat Desktop]# echo "Welcome to httpd -by sunny 20200308" > /var/www/html/index.html
[root@redhat html]# firefox
(process:12672): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed
修改网站数据目录
已知网站目录为/var/www/html,那么是否可自己指定一个目录作为网站的数据目录呢?
[root@redhat web-index]# mkdir /home/wwwroot
[root@redhat web-index]# echo " this is a new Directory" > /home/wwwroot/index.html
[root@redhat web-index]# vim /etc/httpd/conf/httpd.conf
##修改
119 DocumentRoot "/home/wwwroot" ##1
124 <Directory "/home/wwwroot"> ##2
125 AllowOverride None
126 # Allow open access:
127 Require all granted
128 </Directory>
##修改完后重启服务,发现刷新后,界面内容并没有更新,这是因为SELlnux 的问题
[root@redhat web-index]# systemctl restart httpd
禁用SELinux后,再刷新,成功。
##禁用SELinux,临时的,系统重启后会失效
[root@redhat web-index]# setenforce 0
下一篇讲一下SELinux