http:// ##超文本传输协议
http:// 超文本传输协议提供软件:Apache
nginx
stgw
jfe
Tengine
dnf install httpd.x86_64 -y
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
vim /var/www/html/index.html
dnf install httpd.x86_64 -y
3.Apache的启用systemctl enable --now httpd ##开启服务并设定服务位开机启动
firewall-cmd --list-all ##查看火墙信息
firewall-cmd --permanent --add-service=http ##在火墙中永久开启http访问
firewall-cmd --permanent --add-service=https ##在火墙中永久开启https访问
firewall-cmd --reload ##刷新火墙使设定生效
服务名称: httpd
配置文件:
/etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/*.conf ##子配置文件
默认发布目录: /var/www/html
默认发布文件: index.html
默认端口: 80 #http
443 #https
用户: apache
日志: /etc/httpd/logs
//重点是指向:DirectoryIndex
#1.Apache端口修改#
vim /etc/httpd/conf/httpd.conf
Listen 8080 //编辑配置文件,修改端口为8080
firewall-cmd --permanent --add-port=8080/tcp //防火墙加8080端口
firewall-cmd --reload //重新加载防火墙
systemctl restart httpd //重启服务
netstat -antlupe | grep httpd //查看端口有没有加进去
http://172.25.254.100:8080
#2.默认发布文件##
vim /var/www/html/westos.html //编辑另外一个页面
内容
vim /etc/httpd/conf/httpd.conf
DirectoryIndex westos.html index.html //编辑它的默认指向页面
systemctl restart httpd //重启服务
http://172.25.254.100:8080
#3.默认发布目录
mkdir /westos_apache
vim /westos_apache/index.html
semanage fcontext -a -t httpd_sys_content_t ‘/westos_apache(/.*)?’ //修改安全上下文和httpd一致
restorecon -RvvF /westos_apache/ //重新加载安全上下文
vim /etc/httpd/conf/httpd.conf //修改配置文件
documentRoot “/var/westos_apache”
Require all granted
//修改配置文件
systemctl restart httpd
http://172.25.254.100:8080
#实验素材#
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
westosdir’s page
firefox http://192.168.0.11/westos
#1.基于客户端ip的访问控制#
mkdir /var/www/html/westos //创建一个目录
vim /etc/httpd/conf/httpd.conf //修改配置文件
documentRoot “/var/www/html” //修改默认的加载路径
#(1)ip白名单#
Order Deny,Allow
Allow from 172.25.254.41 //允许一个,拒绝所有
Deny from All
#(2)ip黑名单#
Order Allow,Deny
Allow from All //允许所有,拒绝一个
Deny from 172.25.254.41
#2.基于用户认证#
mkdir /var/www/html/westos //创建加密的文件
vim /var/www/html/westos/index.html //编辑加载的页面
在这个路径下面/etc/httpd/:
htpasswd -cm .htpasswd admin //创建用户
vim /etc/httpd/conf/httpd.conf //编辑配置文件
160行:
DirectoryIndex index.html //默认加载的文件
120行:
documentRoot “/var/www/html” //路径
AuthUserfile /etc/httpd/.htpasswd //指定认证文件
AuthName “Please input your name and password” //认证提示语
AuthType basic //认证类型
#Require user admin //允许通过的认证用户 2选1
Require valid-user //允许所有用户通过认证 2选1
systemctl restart httpd //重启服务
htpasswd -cm /etc/httpd/htpasswdfile admin //生成认证文件
注意:
当/etc/httpd/htpasswdfile存在那么在添加用户时不要加-c参数否则会覆盖源文件内容
mkdir -p /var/www/westos.com/{news,wenku}
echo “wenku’s page” >/var/www/westos.com/wenku/index.html
echo “news’s page” > /var/www/westos.com/news/index.html
echo “default’s page” > /var/www/html/index.html
vim /etc/httpd/vhost.conf
documentRoot “/var/www/html”
CustomLog logs/default.log combined
ServerName wenku.westos.com
documentRoot “/var/www/westos.com/wenku”
CustomLog logs/wenku.log combined
ServerName news.westos.com
documentRoot “/var/www/westos.com/news”
CustomLog logs/news.log combined
测试:
在浏览器所在主机中
vim /etc/hosts
192.168.0.11 www.westos.com wenku.westos.ocm news.westos.com
firefox http://www.westos.com
firefox http://wenku.westos.com
firefox http://news.westos.com
//实验步骤:
1、 创建文件目录:(服务器)
mkdir -p /var/www/vhost/westos.org/{news,music,hkk}
echo news.westos.org> /var/www/vhost/westos.org/news/index.html
echo music.westos.org> /var/www/vhost/westos.org/music/index.html
echo hkk.westos.org> /var/www/vhost/westos.org/hkk/index.html
2、编辑配置文件(服务器)
vim /etc/httpd/conf.d/vhost.conf
documentRoot /var/www/html
CustomLog logs/default.log combined
ServerName music.westos.org documentRoot /var/www/vhost/westos.org/music CustomLog logs/music.log combined ServerName news.westos.org documentRoot /var/www/vhost/news.org/news CustomLog logs/news.log combined ServerName hkk.westos.org documentRoot /var/www/vhost/hkk.org/hkk CustomLog logs/hkk.log combined
3、手动解析域名:(浏览器在哪里就在哪里编辑)
172.25.254.241 westos.westos.org news.westos.org music.westos.org hkk.westos.org
//服务器ip
4、重启并测试
systemctl restart httpd
westos.westos.org
news.westos.org
music.westos.org
hkk.westos.org //分别访问,用浏览器
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)