apache
apache的安装部署
yum install httpd -y
yum install httpd-manual
systemctl start httpd
systemctl enable httpd
firewall-cmd --permanent --add-service=http
firewall-cmd --reload
/var/www/html
/var/www/html/index.html ##apache的/目录,默认发布目录
vim /var/www/html/index.html ##apache的默认发布文件
<h1>hello world</h1>
测试
http://172.25.254.105
http://172.25.254.105/manual
apache的基本信息
主配置目录: /etc/httpd/conf
主配置文件: /etc/httpd/conf/httpd.conf
子配置目录: /etc/httpd/conf.d
子配置文件: /etc/httpd/conf.d/httpd.conf
默认发布目录: /var/www/html
默认发布文件: /var/www/html/index.html
默认端口: 80
默认安全上下文: http_sys_content_t
程序开启默认用户: apache
apache日志: /etc/httpd/logs/*
修改默认端口:
vim /etc/httpd/conf/httpd.conf
Listen 8080
firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload
修改默认发布文件:
vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.html test.html ##默认访问顺序
vim /var/www/html/test.html
修改默认发布目录:
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/westos/html"
<Directory "/westos">
Require all granted
</Directory>
vim /westos/html/index.html
登陆权限设置
mkdir /var/www/html/westos
vim /var/www/html/westos/index.html
<h1>拒绝172.25.254.5</h1>
vim /etc/httpd/conf/httpd.conf ##修改默认发布目录并设置172.25.254.5拒绝访问
<Directory "/var/www/html/westos">
Order Allow,Deny ##读取顺序
Allow from All ##允许所有
Deny from 172.25.254.5 ##拒绝172.25.254.5
在172.25.254.5上访问失败
在其他主机上访问成功
密码验证
htpasswd -mc westosuser admin
htpasswd -c westosuser admin1
<Directory "/var/www/html/westos">
AuthUserFile /etc/httpd/conf/westosuser ##用户认证文件
AuthType basic ##认证类型
AuthName "please input your name and password" ##提示语
#Require user admin ##允许admin用户
Require valid-user ##允许所有合法用户
</Directory>
访问时需要验证
验证成功后可以访问
验证失败后显示验证失败
不同域名访问不同主页
vim /var/www/html/index.html
<h1>default page</h1>
vim /var/www/virtual/music/html/index.html
<h1>music's page</h1>
vim /var/www/virtual/news/html/index.html
<h1>news's page</h1>
vim /etc/httpd/conf.d/a_default.conf
<Virtualhost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</Virtualhost>
vim /etc/httpd/conf.d/music.conf
<Virtualhost *:80>
ServerName music.westos.com
DocumentRoot /var/www/virtual/music/html
CustomLog logs/music.log combined
</Virtualhost>
<Directory "/var/www/virtual/music/html">
Require all granted
</Directory>
vim /etc/httpd/conf.d/news.conf
<Virtualhost *:80>
ServerName news.westos.com
DocumentRoot /var/www/virtual/news/html
CustomLog logs/news.log combined
</Virtualhost>
<Directory "/var/www/virtual/news/html">
Require all granted
</Directory>
vim /etc/hosts ##在访问的主机上设置本地解析
访问php页面
yum install php -y
vim /var/www/html/index.php
<?php
phpinfo();
?>
访问cgi页面
mkdir /var/www/html/cgi
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "Hello, World.";
chmod 775 /var/www/html/cgi/index.cgi
vim /etc/httpd/conf.d/a_default.conf
<Directory "/var/www/html/cgi">
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
https安全访问
yum install mod_ssl -y
yum install crypto-utils -y
genkey www.westos.com
output will be written to /etc/pki/tls/certs/www.westos.com.crt
output key written to /etc/pki/tls/private/www.westos.com.key
需要敲击键盘以生成**
vim /etc/httpd/conf.d/ssl.conf
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
加密访问
<Virtualhost *:443>
ServerName login.westos.com
DocumentRoot /var/www/virtual/login/html
CustomLog logs/login.log combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
</Virtualhost>
<Directory "/var/www/virtual/login/html">
Require all granted
</Directory>
<Virtualhost *:80>
ServerName login.westos.com
RewriteEngine On
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
</VirtualHost>
^(/.*)$ ##客户在浏览器中输入的所有字符
https:// ##强制客户加密访问
%{HTTP_HOST} ##客户请求主机
$1 ##表示^(/.*)$的值
[redirect=301] ##临时写入 302永久写入
mkdir -p /var/www/virtual/login/html
vim /var/www/virtual/login/html/index.html
<h1>login's page<h1>
systemctl restart httpd.service
squid服务器
yum install squid -y
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.105 parent 80 0 proxy-only round-robin originserver name=web1
cache_peer 172.25.254.104 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
vim /etc/hosts ##在访问的主机上添加本地解析
172.25.254.205 www.westos.com