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

本文探讨了HTTP服务器中的关键概念,包括deflate_module模块的配置,HTTP如何重定向到HTTPS,深入理解HSTS(HTTP Strict Transport Security)机制以及反向代理的工作原理。通过这些内容,读者可以更好地理解HTTP服务器的安全与性能优化策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值