Linux中apache服务
Posted 正义的朋友
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Linux中apache服务相关的知识,希望对你有一定的参考价值。
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/cq">
Order Deny,ALLOW ##读取顺序
Allow from 172.25.254.4 ##设置允许172。25.254.3登入
Deny from All ##设置拒绝所有人
</Directory>
<Directory "/var/www/html/cq">
Order Deny,ALLOW ##读取顺序
Allow from 172.25.254.4 ##设置允许172。25.254.3登入
Deny from All ##设置拒绝所有人
</Directory>
![](https://image.cha138.com/20210512/f38ee90a3e2e4a89bf1b15941ab89a72.jpg)
systemctl restart httpd
![](https://image.cha138.com/20210512/9c5a2761c002406aa21398ce69204d7a.jpg)
cd /etc/httpd/conf
ls
htpasswd -cm cquser admin 创建访问用户
htpasswd -m cquser admin1 再次创建
![](https://image.cha138.com/20210512/73e1bdb94d5d425faff89d8743c6b21f.jpg)
vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/cq">
AuthUserFile /etc/httpd/conf/cquser
AuthType basic
AuthName "please input your name and password!"
Require user admin
</Directory>
![](https://image.cha138.com/20210512/de07af42a1cd4e5c8be9ed8177a8634e.jpg)
##apach的虚拟主机功能
注释掉之前的配置
创建文件
mkdir /var/www/virtual/news/html
mkdir /var/www/virtual/music/html
vim /var/www/virtual/news/html/index.html
vim /var/www/virtual/music/html/index.html
![](https://image.cha138.com/20210512/b90df19c9c424aab9a16513646a28344.jpg)
cd /etc/httpd/conf.d/
vim a_default.conf
![](https://image.cha138.com/20210512/333e8ec04ba244f183e55a91793159be.jpg)
vim news.conf
![](https://image.cha138.com/20210512/ff95c994e8be45baa2a3b5a75098d625.jpg)
vim music.conf
![](https://image.cha138.com/20210512/e4609cbc3c0b403dbd5026c2a6a6cb8d.jpg)
当这些配置完成之后,需要在浏览器一端设置本地域名解析。
vim /etc/hosts
172.25.254.103 www.westos.com av.westos.com cctv.default.com
测试:
![](https://image.cha138.com/20210512/106e7a64edde442c8a2a1412a2ba652c.jpg)
测试:172.25.254.103/index.php
![](https://image.cha138.com/20210512/fc2151466d2a4bc59c3f80e28e89c794.jpg)
cgi
yum install httpd-manual -y
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\\n\\n";
print \'date\';
chmod 755 index.cgi
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\\n\\n";
print \'date\';
chmod 755 index.cgi
![](https://image.cha138.com/20210512/06ed87cbedf54a5e852a402abf77e4fa.jpg)
然而此时访问却只能访问裸露的代码
此时需要配置 vim /etc/httpd/conf.d/a_default.conf
在manual页上复制
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
![](https://image.cha138.com/20210512/c1f2d3a797bf4009953e895b802e133f.jpg)
systemctl restart httpd
###########################################################
https
yum install mod_ssl -y
yum install crypto-utils -y
![](https://image.cha138.com/20210512/1169cc5bd8ca4bfc8abd04ceeecfaeea.jpg)
![](https://image.cha138.com/20210512/4b18b4f75601415080f30e6040163981.jpg)
genkey www.westos.com 生成证书
vim ssl.conf
crtl+z fg 1 复制锁和钥匙存的目录到这个配置文件里
systemctl restart httpd
crtl+z fg 1 复制锁和钥匙存的目录到这个配置文件里
systemctl restart httpd
![](https://image.cha138.com/20210512/81e760053f4a458b90f7938f51dbd46a.jpg)
此时访问 https://www.westos.com
![](https://image.cha138.com/20210512/bf6b805335db439c917ee4a6c5e1bdcf.jpg)
#################################################################
实现自动加锁
cd /etc/httpd/conf.d/
cp news.conf login.conf
vim login.conf
:%s/news/login 将所有的news换成login
mkdir -p /var/www/virtual/login/html 创建目录
vim /var/www/virtual/login/html/index.html 编写文件
vim /etc/httpd.conf/login.conf
vim /etc//httpd/conf.d/ssl.conf
复制钥匙复制锁
![](https://image.cha138.com/20210512/c998edf7af00447da0cfec0742a307b9.jpg)
systemctl restart httpd
测试;
访问 login.westos.com 注:测试机若没有解析请添加解析 vim/etc/hosts :login.westos.com
结果自动切换到https
##################################################################3
squid
首先在虚拟机上安装squid
yum install squid -y
配置好虚拟机的网关和dns
开启squid
systemctl start squid
netstat -antlupe | grep squid 查看端口
vim /etc/squid/squid.conf
56 http_access allow all
62 取消注释
systemctl restart squid
之后可以通过虚拟机让真机上网
######################################################
squid的缓存
设备
reset的desktop
安装 squid
vim /etc/squid/squid.conf
http_access allow all
# Squid normally listens to port 3128
http_port 80 vhost vport
cache_peer 172.25.254.104 parent 80 0 proxy-only round-robin originserver name=web1
cache_peer 172.25.254.103 parent 80 0 proxy-only round-robin originserver name=web2
cache_peer_domain web1 web2 www.westos.com
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256
systemctl restart squid
vim /etc/hosts
www.westos.com 172.25.254.204
测试:在虚拟机上firefox
www.westos.com
squid的缓存
设备
reset的desktop
安装 squid
vim /etc/squid/squid.conf
http_access allow all
# Squid normally listens to port 3128
http_port 80 vhost vport
cache_peer 172.25.254.104 parent 80 0 proxy-only round-robin originserver name=web1
cache_peer 172.25.254.103 parent 80 0 proxy-only round-robin originserver name=web2
cache_peer_domain web1 web2 www.westos.com
# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256
systemctl restart squid
vim /etc/hosts
www.westos.com 172.25.254.204
测试:在虚拟机上firefox
www.westos.com
以上是关于Linux中apache服务的主要内容,如果未能解决你的问题,请参考以下文章