简介
本文主要介绍在CentOS下,Apache与Nginx 服务的搭建与配置
一、关闭防火墙和selinux
1.关闭防火墙
systemctl status firewalld
systemctl stop firewalld
systemctl status firewalld
systemctl disable firewalld
1.关闭selinux
setenforce 0
getenforce
输入**vi /etc/sysconfig/selinux**
将文件中的SELINUX=**enforcing**改为**disabled**
重启虚拟机生效
二、Web服务器与配置
1.Apache
yum -y install httpd
systemctl start httpd
netstat -lntp | grep httpd
- 查看httpd的主配置文件(/etc/httpd/conf/httpd.conf)
及默认发布网站的目录(/var/www/html)
vim /etc/httpd/conf/httpd.conf
- 配置httpd的子配置文件(/etc/httpd/conf.d/)
cd /etc/httpd/conf.d
<Virtualhost *:80>
DocumentRoot /data
ServerName localhost
<Directory "/data">
AllowOverride None
Require all granted
</Directory>
</Virtualhost>
//创建发布网站目录(这里是/data)
mkdir /data
//重启httpd服务
systemctl restart httpd
输入虚拟机IP地址和端口号
出现此界面说明访问成功
2.Nginx
- 安装并启动Nginx服务(因默认和httpd一样默认使用80端口号,所以需要停止httpd服务)
yum -y install nginx
systemctl stop httpd
systemctl start nginx
netstat -lntp | grep nginx
cd /etc/nginx/conf.d
vim test.conf
server{
listen 81; # 因为default.conf已经使用了80端口,所以这里使用81端口
server_name localhost;
location / {
root /data;
index index.html index.htm;
}
}
//测试nginx的配置和退出
nginx -t
//重新加载nginx配置
nginx -s reload
输入虚拟机IP地址和端口号
出现此界面说明访问成功