nginx:无法处理动态页面,只能处理静态(类似打10086),擅长用于反向代理
prefork:预派生
apache:稳定,擅长动态
正向代理:翻墙
lamp lnmp = linux apache(nginx) mysql php
Apache:提供http协议的访问
http与https的区别
HTTP(超文本传输协议)被用于在Web浏览器和网站服务器之间传递信息。
HTTP协议以明文方式发送内容(不安全),不提供任何方式的数据加密,如果攻击者截取了 Web浏览器和网站 服务器之间的传输报文,就可以直接读懂其中的信息,因此HTTP协议 不适合传输一些敏感 信息,比如信用卡号、密码等。
为了解决HTTP协议的这一缺陷,需要使用另一种协议:
HTTPS( 安全套接字层超文本传输协议,具有安全性的ssl加密传输协议):为了数据传输的安全,HTTPS在HTTP的基础上加入了SSL协议,SSL依靠证书来验证服务器的身份,并为浏览器和服务器之间的通信加密。
HTTP:默认端口80
HTTPS:默认端口443
Apache基本配置
虚拟主机设置
https配置
集成动态内容
访问出问题:服务没开
没加进防火墙
apache
##关闭selinux
#1:apache
企业中常用的web服务,用来提供http://(超文本传输协议)
2:apache的安装部署
(1)yum insatll httpd -y ##apache软件
(2)firewall-cmd --premanent --add-service=http ##火墙允许http
(3)firewall-cmd --reload
(4)firewall-cmd --list-all
(5)yum install -y httpd-manual ##apache的手册
(6)/var/www/html/ ##apache的根目录,默认发布目录
(7)/var/www/html/index.html ##apache的默认发布文件
(8)vim /var/www/html/index.html
<h1> hello westos</h1>
(9)systemctl rsetart httpd
(8)vim /var/www/html/index.html
(9)systemctl rsetart httpd
测试:
直接输入: http://172.25.254.162
http://172.25.254.162/manual ##查看手册
apache的基础信息
apache ##程序开启默认用户
/etc/httpd/logs/* ##apache日志
/etc/httpd/conf ##主配置目录
/etc/httpd/conf/httpd.conf ##主配置文件
/etc/httpd/conf.d/ ##子配置目录
/etc/httpd/conf.d/*.conf ##子配置文件
/var/www/html ##apache的根目录,默认发布目录
/var/www/html/index.html ##apache的根目录,默认发布文件
HTTP:默认端口:80
http_sys_content_t ##默认安全上下文**
vim /etc/httpd/conf/httpd.conf
【1】修改默认端口:
(1) vim /var/www/html/index.html
<h1>hello westos</h1>
(2)vim /etc/httpd/conf/httpd.conf
43行 Listen 8080 ##修改默认端口为8080
(3)firewall-cmd --premanent --add-port=8080/tcp
firewall-cmd --reload
systemctl restart httpd
(4)netstat -tnlp | grep http ##查看端口
测试:
http://172.25.254.162:8080
内容是默认的/var/www/html/index.html 中的编写内容: hello westos
(1) vim /var/www/html/index.html
(2)vim /etc/httpd/conf/httpd.conf
(3)
firewall-cmd --premanent --add-port=8080/tcp
firewall-cmd --reload
测试:
【2】修改默认发布文件:
默认发布文件就是访问apache时没有指定文件名时默认访问的文件
这个文件可以指定多个,有访问顺序
(1)vim /var/www/html/westos
<h1>www.westos.com</h1>
(2)vim /etc/httpd/conf/httpd.conf
164 DirectoryIndex westos index.html ##当westos存在时先访问westos,不存在时直接访问index.html**
systemctl restart httpd
测试
(3):http://172.25.254.162
结果:www.westos.com
(1)vim /var/www/html/westos
(2)vim /etc/httpd/conf/httpd.conf
systemctl restart httpd
【3】修改默认发布目录:
(1) mkdir /westos/html
(2) vim /westos/html/index.html
(3) vim /etc/httpd/conf/httpd.conf
120 DocumentRoot "/westos/html"
121 <Directory "/westos">
122 Require all granted
123</Directory>
systemctl resart httpd
(4)测试:172.25.254.162
test hello
(1)(2)
测试:
【4】 访问控制:
(1) vim /var/www/html/index.html
<h1>172.25.254.162</h1>
(2)mkdir /var/www/html/westos
(3)vim /var/www/html/westos/index.html
<h1>test haha</h1>
(4)vim /etc/httpd/conf/httpd.conf
120 <Directory "/var/www/html/westos">
121 Order Allow ,Deny ##先读逗号前面的即Allow,再读Deny
122 Allow from All
123 Deny from 172.25.254.62 ##不允许212主机访问,读到Deny会覆盖Allow
124 </Directory>
systemctl restart httpd
(5)测试
在172.25.254.162主机访问
输入:172.25.254.162/westos/index.html访问成功
在172.25.54.62访问
输入:172.25.254.162/westos/index.html访问失败
在其他主机不可以访问
**(2,3)
(4)
systemctl restart httpd
(5)
【5】####指定用户访问#######
(1)htpasswd -cm westosuser admin ##生成文件时加 -c 参数
(2) htpasswd -m westosuser admin1
(3)cat westpsuser ##查看到用户的加密字符
(4)vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html/westos"> ##此时默认的index.html文件的路径为/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>
(5) systemctl restart httpd
测试:
(6)172.25.254.162/westos
访问时输入用户和密码
(1,2,3)
(4)vim /etc/httpd/conf/httpd.conf
(5) systemctl restart httpd
【6】 Apache的虚拟主机
(1) mkdir /var/www/virtual/news -p
mkdir /var/www/virtual/music -p
ll /var/www/
(2) vim /var/www/virtual/news/index.html
<h1>www.news.com</h1>
(3) vim /var/www/virtual/music/index.html
<h1>www.music.com</h1>
(4)cd /etc/httpd/conf.d
vim default.conf
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
(5) vim /etc/httpd/conf.d/news.conf
内容:
<VirtualHost *:80>
DocumentName 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>
(6) vim /etc/httpd/conf.d/music.conf
内容: (:%s/news/music)
<VirtualHost *:80>
DocumentName music.westos.com
DocumentRoot /var/www/virtual/music/html
CustomLog logs/news.log combined
</VirtualHost>
<Directory "/var/www/virtual/music/html">
Require all granted
</Directory>
systemctl restart httpd
(7)vim /etc/hosts
内容:
172.25.254.162 www.news.com www.music.com
测试:
(8) 输入: music.westos.com
结果: music.westos.com
输入: news.westos.com
结果:news.westos.com
在62真机:
vim /etc/hosts
172.25.254.162 news.westos.com music.westos.com
先输入www.baidu.com
进入百度网页,点击新闻,网站会自动跳到news.westos.com,音乐也一样 **
(1)(2)
(2)(3)
(4)
vim /etc/httpd/conf.d/default.conf
(5) vim /etc/httpd/conf.d/news.conf
(6) vim /etc/httpd/conf.d/music.conf
(7)vim /etc/hosts
(8)
【7】
php+cgi
PHP:超文本预处理文件,动态页面
(1)vim /var/www/html/index.php
<?php
phpinfo();
?>
(2) yum install php -y
systemctl restart httpd
##cgi
CGI:通用网关接口(CGI)是网站上放置动态内容的最简单的方法
(3)mkdir /var/www/html/cgi
(4) vim /var/www/html/cgi/index.cgi
以下内容可以在172.25.254.112/manual下的 CGI:Dynamic Content中找到
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print `date`;
(5) chmod 775 index.cgi
浏览器:172.25.254.162/cgi/index.cgi
显示出的只是代码,静态
(6) vim /etc/httpd/conf.d/default.conf
<VirtualHost _default_:80>
DocumentRoot /var/www/html
CustomLog logs/default.log combined
</VirtualHost>
<Directory "/var/www/html/cgi"> ##动态页面
Options +ExecCGI
AddHandler cgi-script .cgi
</Directory>
(7) 测试:
在浏览器中:172.25.254.112/cgi/index.cgi
会动态显示时间
**(1)
(2)
systemctl restart httpd
(3)
(4)
(5)
(6)
(7)
**
【8】 apache的ssl
https:访问443端口
http: 访问,
端口
301:永久重定向
(1) yum install mod_ssl -y ##会自动生成sslconf文件,路径在/etc/httpd/conf.d/
systemctl restart httpd
(2)https://172.25.254.162 ,可以访问,正常显示
删除自己已有的证书
##生成自签名证书
(3)yum install crypto-utils -y ##密钥生成器
(4)genkey www.westos.com ##生成证书
将生成的证书 和钥匙写入到ssl.conf配置文件中
(5)vim /etc/httpd/conf.d/ssl.conf
内容:
101 SSLCertificateFile /etc/pki/tls/certs/www.westos.com.crt ##证书
108 SSLCertificateKeyFile /etc/pki/tls/private/www.westos.com.key ##钥匙
(6)systemctl restart httpd
(7)测试
浏览器中:https://172.25.254.112
进行一系列操作,会看到自己的证书
(1)
(2)
(3)生成自签名证书
(4)
(5)
vim /etc/httpd/conf.d/ssl.conf
(6)systemctl restart httpd
(7)
【9】 网页重写
(1) cd /etc/httpd/conf.d/
cp news.conf login.conf
(2)vim login.conf
内容:
<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>
(3) mkdir -p /var/www/virtual/login/html
(4) vim /var/www/virtual/login/html/index.html
内容:
<h1>login.westos.com</h1>
systemctl restart httpd
(5)vim login.conf
##强制重定向
内容:
<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>
(6)vim /etc/hosts
172.25.254.162 login.westos.com
测试:
(7)
输入http://login.westos.com
回车后自动转换为https://login.westos.com
结果:login.westos.com
##^(/.*)$ 表示客户在浏览器中输入的所有字符
##$1:表示^(/.*)$的值
##redirect=301表示强制转换时是永久的
##%{HTTP_HOST}表示客户请求主机
**(1)
(2)vim login.conf
(3)
(4) vim /var/www/virtual/login/html/index.html
(5)vim /etc/httpd/cond.f/login.conf
(6)
(7)
【10】 WSGI 语言 (翻译)
hostnamectl set-hostname Apache.westos.com
WSGI提供python 语言支持
WSGIScriptAlias / /var/www/wsgi/script.wsgi
##script.wsgi的路径
(1)yum install mod_wsgi.x86_64 -y
(2)wget http://172.252..............在老师那下载,
cat script.wsgi:有内容
(3)mkdir /var/www/wsgi -p ##建立wsgi目录
将(2)下载的文件移到/var/www/html下
(4)vim /etc/httpd/conf.d/vhost.conf ##手动写子配置文件
内容:<VirtualHost *:80>
ServerName www.westoswsgi.com ##访问时输入的网页
WSGIScriptAlias / /var/www/wsgi/script.wsgi ##script.wsgi的路径
</VirtualHost>
ls /etc/httpd.conf.d/ ##有 vhost.conf ##子配置文件
(5)vim /etc/hosts
内容:172.25.254.112 www.westoswsgi.com
(6)systemctl restart httpd
测试:
(7)
www.westoswsgi.com
结果:UNIX EPOCH time is now:1565402902.46 (不定)
(1)
(3)
(4)vim /etc/httpd/conf.d/vhost.conf
(5)vim /etc/hosts
(6) systemctl restart httpd
(7)