http 软件提供超文本传输协议
apache 同步阻塞模式 稳定(用于认证)
ndinx 异步非阻塞模式 高效(用于浏览)
apache服务:
http服务的默认端口为80
http中的默认文件为index.html;浏览器中http后的’/’=/var/www/html;ftp后的’/’=/var/ftp
准备环境:
yum install httpd
systemctl start httpd
systemctl stop firewall
1.http服务基本配置的修改:
(1)服务端口修改:
vim /etc/httpd/conf/httpd.conf
listen 8080
systemctl restart httpd
验证:浏览器172.25.254.107:80 访问失败
172.25.254.107:8080 访问成功
mkdir /westos/html -p
vim /westos/html/index.html
文件中写入redhat
vim /etc/httpd/conf/httpd.conf
注释DocumentRoot "/var/www/html"
DocumentRoot "/westos/html"
"/westos">
require all granted
</Directory>
验证:浏览器:172.25.254.107
显示redhat
vim /westos/html/test.html
文件中写入westos
vim /etc/httpd/conf/httpd.conf
DocumentRoot "/westos/html"
"/westos">
require all granted
DirectoryIndex test.html
验证:浏览器:172.25.254.107
显示westos
mkdir /westos/html/linux
vim /westos/html/linux/index.html
写入index's page
vim /westos/html/linux/test.html
写入test's page
验证:浏览器:172.25.254.107/linux
显示test's page
vim /etc/httpd/conf/httpd.conf
"/westos/html/linux">
DirecoryIndex index.html
验证:浏览器:172.25.254.107/linux
显示index’s page
2. http服务的登陆限制:
1.ip访问方式
vim /etc/httpd/conf/httpd.conf(白名单)
Order Deny,Allow Deny和allow是有顺序的,谁在前,谁将会被首先读取后读取的会覆盖前面的内容
Allow from 172.25.254.7
Deny from All
systemctl restart httpd
验证:172.25.254.7浏览器172.25.254.107/westos:可以访问
其他主机浏览器172.25.254.107/westos: 访问失败
vim /etc/httpd/conf/httpd.conf (黑名单)
Order Allow,Deny
Allow from All
Deny from 172.25.254.7
systemctl restart httpd
验证:172.25.254.7浏览器172.25.254.107/westos:访问失败
其他主机浏览器172.25.254.107/westos: 访问成功
cd /etc/httpd/
htpasswd -cm apacheuser admin(若apacheuser目录存在,则不需要加-c)
htpasswd -cm apacheuser lee
vim /etc/httpd/conf/httpd.conf
注释ip访问方式
<Directory "/var/www/html/westos">
AuthUserFile /etc/httpd/apacheuser
AuthName "Please input user and password!!!"
AuthType basic
# Require user admin(指定用户访问)
Require valid-user(apacheuser中的所有用户都可以访问)
Directory>
systemctl restart httpd
验证:浏览器172.25.254.107/westos (需要用户密码登陆)
vim /var/www/html/index.html
写入default's page
mkdir /var/virtual/westos.com/news/ -p
mkdir /var/virtual/westos.com/music/ -p
vim /var/virtual/westos.com/news/index.html
写入new's page
vim /var/virtual/westos.com/music/index.html
写入music's page
书写各自的配置文件:
vim /etc/httpd/conf.d/default.conf
DocumentRoot /var/www/html
CustomLog "logs/default.log" combined
vim /etc/httpd/conf.d/news.conf
80>
ServerName news.westos.com
DocumentRoot "/var/www/virtual/westos.com/news"
CustomLog "logs/news.log" combined
vim /etc/httpd/conf.d/music.conf
80>
ServerName music.westos.com
DocumentRoot "/var/www/virtual/westos.com/music"
CustomLog "logs/music.log" combined
systemctl restart httpd
用浏览器访问的主机:
vim /etc/hosts
172.25.254.107 www.westos.com news.westos.com music.westos.com login.westos.com 域名解析
验证:浏览器 www.westos.com 显示default’s page
news.westos.com 显示new’s page
music.westos.com 显示music’s page
4.https证书和钥匙的生成(https的端口为443)
yum install mod_ssl crypto-utils -y
genkey www.westos.com
next-->1024 next-->no-->不选 next-->看截图
vim /etc/httpd/conf.d/ssl.conf
更改证书和钥匙
验证:浏览器 https://www.westos.com下载可以看到(清缓存、删记录)
5.http–>https的转换
vim /etc/httpd/conf.d/login.conf
Servername login.westos.com
DocumentRoot "/var/www/virtual/westos.com/login"
CustomLog "logs/music.log" combined
SSLEngine on
SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt
SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key
Require all granted
ServerName login.westos.com
RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=301]
mkdir /var/www/virtual/westos.com/login -p
vim /var/www/virtual/westos.com/login/index.html
写入login's page
验证:浏览器 login.westos.com 输入域名时默认为http:// 自动转换为https:// 有锁
6.网页测试:
php的网页测试:
yum install php -y
vim /etc/httpd/conf/httpd.conf
DirectoryIndex index.php index.html
vim /var/www/html/index.php
phpinfo();
?>
systemctl restart httpd
验证:浏览器 172.25.254.107
vim /var/www/html/cgi/index.cgi
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
vim /etc/httpd/conf.d/default.conf
"/var/www/html/cgi"
Options +ExecCGI
AddHandler cgi-script .cgi
DirectoryIndex index.cgi
chmod +x /var/www/html/cgi/index.cgi 给文件加执行权限
验证:浏览器172.25.254.107/cgi/index.cgi 输出时间
7.论坛的搭建:
cd /var/www/html/
下载论坛的安装压缩包
get D*
chmod 777 upload -R
systemctl restart httpd
验证:浏览器 172.25.254.107/upload 显示论坛安装登陆
yum install php-mysql
刷新网页
8.正向代理:
保证一台主机可以上网
可以上网的主机:
yum install squid
vim /etc/squid/squid.conf
http_access allow all
cache_dir ufs /var/spool/squid 100 16 256
systemctl start squid
不能上网的主机:
浏览器–>preference–>advanced–>network–>settings–>manual proxy configuration–>http proxy 能上网的主机ip port 3128–>ok
验证:www.baidu.com 可以上网
9.反向代理:
desktop虚拟机: 安装apache服务,充当代理主机
server虚拟机: yum install squid -y 安装squid服务
vim /etc/squid/squid.conf
httpd_access allow all
http_port 80 vhost vport
cache_peer 172.25.254.107 parent 80 0 proxy-only
cache_dir ufs /var/spool/squid 100 16 256
systemctl stop firewalld