httpd
网站服务
工作目录
/var/www/html
主配置文件
/etc/httpd/conf/httpd.conf
#############################
内容详解:
ServerRoot “/etc/httpd” #服务的根目录
Listen 80 #监听端口80
Include conf.modules.d/.conf #包含文件位置
User apache #服务使用者apache
Group apache #服务所在组 apache
ServerAdmin root@localhost #管理员邮箱
#根权限
AllowOverride none
Require all denied
DocumentRoot “/var/www/html” #工作目录位置
<Directory “/var/www”>
AllowOverride None
Require all granted
<Directory “/var/www/html”> #工作目录权限
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
ErrorLog “logs/error_log” #错误日志位置
LogLevel warn #错误记录
IncludeOptional conf.d/.conf #其他
#######################################
httpd默认是80端口
欢迎页
/etc/httpd/conf.d/welcome.conf
默认主页
etc/httpd/conf.d/welcome.conf
注意:
修改所有*.conf *.cfg *.config 后都需要重启服务才能生效
httpd虚拟主机(虚拟服务器,虚拟网络)
1.以域名区分
#编辑配置文件
cd /etc/httpd/conf.d/
vim 1.conf
################
<VirtualHost *:80>
ServerName 1.com #访问的域名
DocumentRoot “/web/html1” #服务目录
<Directory “/web/html1”> #服务目录权限
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
<VirtualHost *:80>
ServerName 2.com
DocumentRoot “/web/html2”
<Directory “/web/html2”> #工作目录权限
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
##########################
建立对应的目录
mkdir -p /web/html1
mkdir -p /web/html2
编辑服务主页
echo 1.com > /web/html1/index.html
echo 2.com > /web/html2/index.html
检查错误
httpd -t
重启服务
systemctl restart httpd
添加dns静态解析
vim /etc/hosts
###############
127.0.0.1 1.com
127.0.0.1 2.com
###############
查看防火墙·
firewall-cmd --list-all
验证
curl 1.com
curl 2.com
2.以端口区分
#####################
Listen 91 #先用netstat -anp|grep -w 端口 (查看是否被使用)
Listen 92
<VirtualHost *:91> #使用端口区分网站
ServerName 4321.com #访问的域名
DocumentRoot “/var/www/html” #服务目录
<Directory “/var/www/html”> #服务目录权限
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
<VirtualHost *:92>
ServerName qwert.com
DocumentRoot “/var/www/html2”
<Directory “/var/www/html2”> #工作目录权限
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
####################
进入到配置文件
Vim /etc/httpd/conf/httpd.conf
添加91 92 端口号
Listen 91
Listen 92
添加防火墙端口 91 92
#列:firewall-cmd --add-port=91/tcp
firewall-cmd --add-port=92/tcp
可以加 --permanent 使永久生效
#重新加载防火墙
firewall-cmd --reload
################################
建立对应的目录
mkdir -p /web/html1
mkdir -p /web/html2
编辑服务主页
echo 4321.com > /web/html1/index.html
echo qwert.com > /web/html2/index.html
检查错误
httpd -t
重启服务
systemctl restart httpd
开机自启
systemctl enable httpd
查看防火墙
firewall-cmd --list-all
验证
curl 127.0.0.1:91
curl 127.0.0.0:92
#grep正则
grep -v “#” 文件名|grep -v “^$” 删除含有#和空格的行