时间:2022-12-14 10:27:55 | 栏目:Linux | 点击:次
安装apche软件:dnf install httpd.x86_64 -y
systemctl enable --now
httpdsystemctl enable --now httpd
firewall-cmd --permanent --add-service=http
irewall-cmd --permanent --add-service=https
firewall-cmd --reload
apche的基本信息
httpd
/etc/httpd/conf/httpd.conf
/etc/httpd/conf.d/*.conf
/var/www/html
/etc/httpd/logs
(1)更改apche服务的端口号
netstat -antlupe |grep httpd
/etc/httpd/conf/httpd.conf
,修改端口号systemctl restart httpd
netsat -antlupe | grep httpd
firewall-cmd --permanent --add-port=888/tcp
firewall-cmd --reload
(2)修改apche的默认发布文件
cd /var/www/html
index.html
默认发布文件就是访问apache时没有指定文件名,即默认访问的文件,此文件可以指定多个,但有访问顺序。
westo.html
/etc/httpd/conf/httpd.conf
systemctl restart httpd
(3)修改apche的默认发布目录
mkdir -p /westos/html/
vim /westos/html/index.html
/etc/httpd/conf/httpd.conf
systemctl restart httpd
systemctl restart httpd
http://172.25.254.144/westos/
(1)白名单
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd
ip=172.25.254.144的主机不在白名单内,无法访问http://172.25.254.44/westos
(2)ip黑名单
vim /etc/httpd/conf/httpd.conf
ip=172.25.254.144不在黑名单内,可以正常访问http://172.25.254.44/westos
(1)允许部分用户通过认证访问共享目录
htpasswd -cm /etc/httpd/htpasswdfile linux
htpasswd -m /etc/httpd/htpasswdfile westos
vim /etc/httpd/conf/httpd.conf
(2)允许所有用户通过认证访问共享目录
vim /etc/httpd/conf/httpd.conf
systemctl restart httpd
虚拟主机:在一台真实主机上建立多个站点(多个域名),通过域名访问一台主机的不同网页,从网络地址看似乎有多个主机,这些主机被称为虚拟主机
DNS解析域名的ip
建立linux,news,media的默认发布目录: mkdir /var/www/westos.com/{linux,news,media} inux的默认发布文件: echo "<h1>hello linux</h1>" > /var/www/westos.com/news/index.html news的默认发布文件:echo "<h1>hello news </h1>" > /var/www/westos.com/news/index.html media的默认发布文件:echo "<h1>hello media </h1>" > /var/www/westos.com/media/index.html
/etc/httpd/conf.d/vhost.conf
/etc/hosts
(1)安装加密插件
(2)生成私钥: openssl genrsa -out /etc/pki/tls/private/www.westos.com.key
(3)生成证书签名文件:openssl req -new -key /etc/pki/tls/private/www.westos.com.key -out /etc/pki/tls/cert/www.westos.com.csr
(4)生成证书:
openssl x509 -req -days 365 -in /etc/pki/tls/certs/www.westos.com.csr -signkey /etc/pki/tls/private/www.westos.com.key -out /etc/pki/tls/certs/www.westos.com.crt ## x509:证书格式 ## -req请求 ## -in加载签证名称 ## -signkey
/etc/httpd/conf.d/ssl.conf
/etc/httpd/conf.d/vhost.conf
systemctl restart httpd
在浏览器中输入media.westos.com会自动跳转到如下界面
(1)apche的子配置文件并编辑:/etc/httpd/conf.d/vhost.conf
(2)重启服务:systemctl restart httpd
(3)测试,输入域名后会自动加载https
(1) 配置squid客户端(该主机可以上网)
/etc/squid/squid.conf
systemctl start squid.service
(2)客户端:在不能上网的主上测试,在浏览器中输入:www.baidu.com不能访问
但是在客户端主机在仍然不能ping通www.baidu.com
node1:没有apache服务的虚拟机172.25.254.244
node2:能正常使用apache服务的虚拟机172.25.254.193,配置apache的发布文件
php
重启apache服务:systemctl restart httpd.service
测试:http://172.25.254.144/index.php
cgi
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
cd /var/www/html/cgi
chmod +x index.cgi
./var/www/html/cgi/index.cgi
测试:http://172.25.254.144/cgi/index.cgi
编辑虚拟主机的配置文件:vim /etc/httpd/conf.d/vhost.conf
重启服务:systemctl restart httpd.service
测试:http://172.25.254.144/cgi/index.cgi