CentOS系统WEB服务器配置
一个小白初次写博客,肯定会有很多很多错误,仅是分享,大家见谅!
准备
一台可以上网的电脑
CentOS系统的iOS文件
VMware 虚拟机
开始吧
1.在VMware上安装CentOS系统。
2.安装httpd服务。
[root@centos-8 admin]# yum -y install httpd
(代码大多要在root中进行[admin@centos-8 ~]$ su root
)
3.配置Apache
进入主配置文件[root@centos-8 admin]# vim /etc/httpd/conf/httpd.conf
(曾经觉得vim难用一直gedit。。。现在“真香”)
<Directory>
这之间为一组配置
</Directory>
首先更改Listen项(该项决定了Apache的监听地址和监听端口,大约45行)
这里让它侦听本地就行了。
然后配置网页的HTML文件位置(大约128行)
默认/var/www/html
就好了。
下面这些也可以配置一下
紫色的都是可以改的,分别为 端口号 网页加载路径 该路径权限 允许谁访问
然后重启服务 [root@centos-8 admin]# systemctl restart httpd
(每次更改配置文件后都要重启)
4.进行防火墙设置
查看防火墙状态[root@centos-8 admin]# systemctl status firewalld
running即为开启状态。(q退出)
如果没开,启动防火墙。[root@centos-8 admin]# systemctl start firewalld.service
5.开放TCP的80端口并重载防火墙
[root@centos-8 admin]# firewall-cmd --zone=public --add-port=8080/tcp --permanent
[root@centos-8 admin]# firewall-cmd --reload
查看防火墙开放端口 [root@centos-8 admin]# firewall-cmd --zone=public --list-ports
因为我后来用的8080端口,这里有两个。
6.编辑html文件测试网页
创建index.html 文件
[root@centos-8 admin]# cd /var/www/html
[root@centos-8 html]# touch index.html
[root@centos-8 html]# vi index.html
随便输入个hello word什么的就行。
7.开始测试
首先查看Apache状态[root@centos-8 html]# systemctl status httpd
如果关闭,就开启它。[root@centos-8 html]# systemctl start httpd
用ifconfig
查看ip,打开浏览器访问。
看见 hello word 当然就成功了!
最后
我之后在将index 换为网上下载的模板后,在物理机上访问会出现异常。
控制台查看是js 和css 等文件存在权限问题。
一番百度终于。。。。。。
上链接 ywCSD
方法如下:
关闭SELinux
修改/etc/selinux/config 文件vim /etc/selinux/config
将SELINUX=enforcing改为SELINUX=disabled
重启机器即可。
真的是万分感谢 !
最终网页展示了它本来的模样。
当然,文件的权限还是要改的,我是直接简单粗暴 777 。。。。