http的压缩、重定向、反向代理

deflate_module 模块

配置文件

<virtualhost *:80>
  documentroot "/data/asite"
  servername www.a.com
  <directory "/data/asite">
    require all granted
  </directory>
  setoutputfilter deflate  // 启用delflate
  deflatecompressionlevel 9 //压缩级别为9
   -- 对哪些文件进行压缩                                                                                                             
  AddOutputFilterByType DEFLATE text/plain
  AddOutputFilterByType DEFLATE text/html
  AddOutputFilterByType DEFLATE application/xhtml+xml
  AddOutputFilterByType DEFLATE text/xml
  AddOutputFilterByType DEFLATE application/xml
  AddOutputFilterByType DEFLATE application/x-javascript
  AddOutputFilterByType DEFLATE text/javascript
  AddOutputFilterByType DEFLATE text/css
</virtualhost>

curl命令查看

[root@Centos6-43-6 ~]# curl -I --compressed www.a.com
HTTP/1.1 200 OK
Date: Thu, 30 Jan 2020 05:44:09 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Thu, 30 Jan 2020 05:30:20 GMT
ETag: "172c-59d54c0bd73c2-gzip"
Accept-Ranges: bytes
Vary: Accept-Encoding
Content-Encoding: gzip  //使用了gzip压缩
Content-Length: 1029
Content-Type: text/html; charset=UTF-8

http重定向https

redirect tmp / https://www.a.com/
redirct permanent https://www.a.com/

在这里插入图片描述
解决产生循环跳转的问题

RewriteEngine on
RewriteRule ^(/.*)$ https://%{HTTP_HOST}$1 [redirect=302]

两次请求不安全,要用到下面的技术解决

HSTS

HSTS:http strict transport security
客户端第一次访问httpd服务器,服务器会返回给客户端 HSTS信息,如 “hsts 302 https://www.a.com”,客户端会缓存信息"http https://,再加上缓存时间",第二次访问就直接访问缓存中的路径

Header always set Strict-Transport-Security "max-age=31536000"   --以秒为单位,缓存一年时间

反向代理

httpd反向代理服务器

[proxy_httpd]# yum install httpd -y
[proxy_httpd]# vim /etc/httpd/conf.d/proxy.conf
<virtualhost *:80>
	documentroot "/data/proxy"
	servername www.proxy.com
	proxypass "/" "http://www.real.com"
	proxypassreverse "/" "http://www.real.com"
</virtualhost>

vim /etc/hosts
192.168.43.17 www.real.com

systemctl start httpd

realhttpd服务器

[realhttpd]# yum install httpd -y
[realhttpd]# echo real > /var/www/html/index.html
[realhttpd]# systemctl start httpd

客户端访问

[client]# vim /etc/hosts
192.168.43.7 www.proxy.com

[client]# curl http://www.proxy.com
发布了61 篇原创文章 · 获赞 1 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/studywinwin/article/details/104115065