步骤:
1,安装docker-compose,因为用docker nginx
2,创建docker-compose.yml文件
version: '3.1'
services:
nginx:
restart: always
image: nginx:1.19.2-alpine
container_name: my-nginx
ports:
- 80:80
- 443:443
volumes:
- "./conf/nginx.conf:/etc/nginx/nginx.conf"
- "./wwwroot:/usr/share/nginx/wwwroot"
- "./log:/var/log/nginx"
3,nginx.conf
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
gzip on; #开启gzip
gzip_min_length 1k; #低于1kb的资源不压缩
gzip_comp_level 3; #压缩级别【1-9】,越大压缩率越高,同时消耗cpu资源也越多,建议设置在4左右。
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; #需要压缩哪些响应类型的资源,多个空格隔开。不建议压缩图片,下面会讲为什么。
gzip_disable "MSIE [1-6]\."; #配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip
gzip_vary