sudo wget http://dlib.net/files/dlib-19.24.tar.bz2下载需要的文件。

sudo tar jxf dlib-19.24.tar.bz2进行解压。

sudo mkdir /nginx/dlib在nginx安装目录/nginx创建一个新的目录dlib。

配置文件里边的内容如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
alias dlib/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
sudo cp -r dlib-19.24/docs/* /nginx/dlib/把dlib-19.24/docs/里边所有的文件都复制到/nginx/dlib/里边。

nginx进行启动。

在浏览器里边输入ip,并且按下回车。

我下边的配置文件的内容会压缩文件:
worker_processes 1;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
server {
listen 80;
server_name localhost;
access_log /nginx/logs/Sea123.access.log main;
location / {
alias dlib/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
可以使用nginx -t -c /nginx/conf/nginx.conf验证一下配置文件正误。

要是已经打开nginx,可以使用nginx -s reload重新加载配置文件启动。

在Firefox浏览器中输入ip,然后按下F12打开开发者工具,选择网络,就可以看到一些信息,可以看到有些文件大小数字比较大,但是传输数值比较小。

有冗余度的信息,才有压缩的价值。比如,用ASCII码编码的HTML、TXT、JSON这些人类可读的信息,由于人类语言的大量冗余性,有很大的压缩空间。但是JPG这些被压缩过的图片,再压缩就没有效果了,甚至由于多增加了一些压缩控制信息而增大体积。从图中就可以看到类型为png和gif,传输反而大于大小。
下边的配置文件加上了set $limit_rate 1k;这条显示传输速度的指令:
worker_processes 1;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
gzip on;
gzip_min_length 1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;
server {
listen 80;
server_name localhost;
access_log /nginx/logs/Sea123.access.log main;
location / {
alias dlib/;
set $limit_rate 1k;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
nginx -s reload重新加载配置文件启动。

在Firefox浏览器中输入ip,然后按下F12打开开发者工具,选择网络,选择禁用缓存,可以看到传输时间明显加大,原先需要大小为26.27kB的文件,只需要48毫秒,现在需要7037毫秒。

此文章为10月Day 9学习笔记,内容来源于极客时间《Nginx 核心知识 150 讲》















![[ZJCTF 2019]NiZhuanSiWei - 伪协议+文件包含+反序列化](https://img-blog.csdnimg.cn/cfcabeaa8ff14d6ca7e5e821a911c6b9.png#pic_center)



