1. Nginx 基本功能配置

news2024/9/22 13:39:53

Nginx 目录信息

图 为 windows 版本的。

在这里插入图片描述

进入Nginx的主目录我们可以看到这些文件夹

client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp

其中这几个文件夹在刚安装后是没有的,主要用来存放运行过程中的临时文件

client_body_temp fastcgi_temp proxy_temp scgi_temp

目录信息:

conf

用来存放配置文件相关 , 主要关注 nginx.conf

在这里插入图片描述

html

用来存放静态文件的默认目录 html、css等

在这里插入图片描述

sbin

nginx的主程序

logs

存放日志信息

nginx.conf 默认配置


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

基本运行原理

在这里插入图片描述

Nginx 配置使用

配置语法

nginx.conf 结构图可以这样概括:

main        # 全局配置,对全局生效
├── events  # 配置影响 Nginx 服务器或与用户的网络连接
├── http    # 配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置
│   ├── upstream # 配置后端服务器具体地址,负载均衡配置不可或缺的部分
│   ├── server   # 配置虚拟主机的相关参数,一个 http 块中可以有多个 server 块
│   ├── server
│   │   ├── location  # server 块可以包含多个 location 块,location 指令用于匹配 uri
│   │   ├── location
│   │   └── ...
│   └── ...
└── ...

一个 Nginx 配置文件的结构就像 nginx.conf 显示的那样,配置文件的语法规则:

配置文件由指令与指令块构成;
每条指令以 ; 分号结尾,指令与参数间以空格符号分隔;
指令块以 {} 大括号将多条指令组织在一起;
include 语句允许组合多个配置文件以提升可维护性;
使用 # 符号添加注释,提高可读性;
使用 $ 符号使用变量;
部分指令的参数支持正则表达式;

Nginx 的典型配置:

user  nginx;                        # 运行用户,默认即是nginx,可以不进行设置
worker_processes  1;                # Nginx 进程数,一般设置为和 CPU 核数一样
error_log  /var/log/nginx/error.log warn;   # Nginx 的错误日志存放目录
pid        /var/run/nginx.pid;      # Nginx 服务启动时的 pid 存放位置

events {
    use epoll;     # 使用epoll的I/O模型(如果你不知道Nginx该使用哪种轮询方法,会自动选择一个最适合你操作系统的)
    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"';

    access_log  /var/log/nginx/access.log  main;   # Nginx访问日志存放位置

    sendfile            on;   # 开启高效传输模式
    tcp_nopush          on;   # 减少网络报文段的数量
    tcp_nodelay         on;
    keepalive_timeout   65;   # 保持连接的时间,也叫超时时间,单位秒
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;      # 文件扩展名与类型映射表
    default_type        application/octet-stream;   # 默认文件类型

    include /etc/nginx/conf.d/*.conf;   # 加载子配置项
    
    server {
    	listen       80;       # 配置监听的端口
    	server_name  localhost;    # 配置的域名
    	
    	location / {
    		root   /usr/share/nginx/html;  # 网站根目录
    		index  index.html index.htm;   # 默认首页文件
    		deny 172.168.22.11;   # 禁止访问的ip地址,可以为all
    		allow 172.168.33.44; # 允许访问的ip地址,可以为all
    	}
    	
    	error_page 500 502 503 504 /50x.html;  # 默认50x对应的访问页面
    	error_page 400 404 error.html;   # 同上
    }
}

在这里插入图片描述

参考链接: https://www.nginx.org.cn/article/detail/545

html 404 配置

html 目录下 默认有 index.html 和 50x.html 页面

输入网址: http://localhost/

在这里插入图片描述

添加 404 页面

输入一个不存在的网址: http://localhost/yjl.html

在这里插入图片描述

![image.png](https://img-blog.csdnimg.cn/img_convert/c809e9c1f87b8690c05ee812b35cb311.png#averageHue=#fdfcfc&clientId=u06b3cd56-2022-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=704&id=u99027495&margin=[object Object]&name=image.png&originHeight=704&originWidth=1212&originalType=binary&ratio=1&rotation=0&showTitle=false&size=58266&status=done&style=none&taskId=uf3f02fd5-567c-41b9-8261-f86603ce906&title=&width=1212)

将 #error_page 404 /404.html; 放开 , 并且在 html 页面 编写一个 404.html 信息

在这里插入图片描述

再访问网址: http://localhost/yjl.html

在这里插入图片描述

404 跳转到 50x.html

在这里插入图片描述

在这里插入图片描述

404 跳转到首页

  location / {
            root   html;
            index  index.html index.htm;
			# 试图访问某个文件, 如果在 就使用原文件,如果不在,就用  /index.html
			try_files $uri $uri/ /index.html;
        }

再访问网址: http://localhost/yjl.html , 跳转到 index.html 页面

![image.png](https://img-blog.csdnimg.cn/img_convert/4c36bcfbf2af654483bc6cd0427c507a.png#averageHue=#fbf9f8&clientId=u06b3cd56-2022-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=306&id=u60d41810&margin=[object Object]&name=image.png&originHeight=306&originWidth=1100&originalType=binary&ratio=1&rotation=0&showTitle=false&size=26131&status=done&style=none&taskId=u427bc03d-104d-456c-b7c5-5dab76c096e&title=&width=1100)

html 页面配置

往 html 页面里面放置一个 js 项目 Stock_Page, 那么访问时可以:

在这里插入图片描述

http://localhost/Stock_Page/page.html

在这里插入图片描述

root 配置静态资源

上面是将 Stock_Page 项目放置在 html 目录下, 实际应用中,一般都是将 项目 单独放置, 不放置在 html 下。 进行动态的配置。

Stock_Page 放置在 目录 : C:\Users\20481\Downloads\nginx-1.22.1
在这里插入图片描述

    	location /Stock_Page {
			root C:\\Users\\20481\\Downloads\\nginx-1.22.1;
			index page.html page.htm;
		}
        location / {
            root   html;
            index  index.html index.htm;
			# 试图访问某个文件, 如果在 就使用原文件,如果不在,就用  /index.html
			try_files $uri $uri/ /index.html;
        }

输入 网址 : http://localhost/Stock_Page/page.html 可以查看页面

使用 root 时, 是 location /访问地址 , 对应的 就是 文件夹名, 这两个要一一对应。

alias 配置静态资源

location /Stock_Page {
			root C:\\Users\\20481\\Downloads\\nginx-1.22.1;
			index page.html page.htm;
		}
		location /Stock {
			alias C:\\Users\\20481\\Downloads\\nginx-1.22.1\\Stock_Page;
			index page.html page.htm;
		}
        location / {
            root   html;
            index  index.html index.htm;
			# 试图访问某个文件, 如果在 就使用原文件,如果不在,就用  /index.html
			try_files $uri $uri/ /index.html;
        }

使用 alias 时 , location /网址 只是一个引入, alias 会找真实的地址路径。

http://localhost/Stock/page.html

即可以访问信息。

root 和 alias 的区别:

root用来设置根目录,而alias在接受请求的时候在路径上不会加上location

1)alias指定的目录是准确的,即location匹配访问的path目录下的文件直接是在alias目录下查找的;
2)root指定 的目录是location匹配访问的path目录的上一级目录,这个path目录一定要是真实存在root指定目录下的;
3)使用 alias标签的目录块中不能使用rewrite的break(具体原因不明);
另外,alias指定的目录后面必须要加上"/“符 号!!
4)alias虚拟目录配置中,location匹配的path目录如果后面不带”/“,
那么访问的url地址中这个path目录后 面加不加”/“不影响访问,访问时它会自动加上”/“;
但是如果location匹配的path目录后面加上”/“,那么访问的url地 址中这个path目录必须要加上”/“,
访问时它不会自动加上”/“。如果不加上”/“,访问就会失败!
5)root目录配置 中,location匹配的path目录后面带不带”/",都不会影响访问。

配置静态资源

location ~ ^/(images|js|css|flash|media|static)/ {
    root C:\\Users\\20481\\Downloads\\nginx-1.22.1\\staticFile;
    #过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
    expires 30d;
}

配置动态反向代理

location /StockApi {
    # 把 /stock 路径下的请求转发给真正的后端服务器
    rewrite  ^/(.*)$ /$1 break;
    proxy_pass http://127.0.0.1:8088$request_uri;
    fastcgi_buffers 8 128k;
    send_timeout 60;
    client_max_body_size     100m;
}

这样,访问 /StockApi/user/1 /StockApi/stock/002415
就可以访问到对应的后端接口请求信息。

location 配置规则

使用一个location 使用正则 location 前缀
/ 通用匹配,任何请求都会匹配到。
= 精准匹配,不是以指定模式开头
~ 正则匹配,区分大小写
~* 正则匹配,不区分大小写
^~ 非正则匹配,匹配以指定模式开头的location

location匹配顺序:

多个正则location直接按书写顺序匹配,成功后就不会继续往后面匹配

普通(非正则)location会一直往下,直到找到匹配度最高的(最大前缀匹配)

当普通location与正则location同时存在,如果正则匹配成功,则不会再执行普通匹配

所有类型location存在时,“=”匹配 > “^~”匹配 > 正则匹配 > 普通(最大前缀匹配)

配置负载均衡

	upstream myproxy{
		server localhost:8088;
		server 127.0.0.1:8088; 	 
	}
    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


		location /StockApi {
			# 把 /stock 路径下的请求转发给真正的后端服务器
			rewrite  ^/(.*)$ /$1 break;
			proxy_pass http://myproxy$request_uri;
			fastcgi_buffers 8 128k;
			send_timeout 60;
			client_max_body_size     100m;
		}
}

负载均衡配置权重

	upstream myproxy{
		server localhost:8088 weight = 10 down;
		server 127.0.0.1:8088 weight = 1; 	
		server 192.168.100.54:8088 weight = backup; 			
	}

down:表示当前的server暂时不参与负载

weight:默认为1.weight越大,负载的权重就越大。

backup: 其它所有的非backup机器down或者忙的时候,请求backup机器。

upstream myproxy{
		server localhost:8088 weight = 10 down;
		server 127.0.0.1:8088 weight = 10 max_fails=5 fail_timeout=10s; 	
		server 127.0.0.1:8088 weight = 10 max_fails=5 fail_timeout=10s; 	
		server 192.168.100.54:8088 weight = backup; 			
	}

参考链接: https://blog.csdn.net/LL845876425/article/details/97621365

rewrite 使用

rewrite语法格式及参数语法:

rewrite是实现URL重写的关键指令,根据regex (正则表达式)部分内容, 重定向到replacement,结尾是flag标记。

rewrite [flag];

关键字 正则 替代内容 flag标记

关键字:其中关键字error_log不能改变

正则:perl兼容正则表达式语句进行规则匹配

替代内容:将正则匹配的内容替换成replacement

flag标记:rewrite支持的flag标记

rewrite参数的标签段位置:

server,location,if

flag标记说明:

last #本条规则匹配完成后,继续向下匹配新的location URI规则
break #本条规则匹配完成即终止,不再匹配后面的任何规则
redirect #返回302临时重定向,浏览器地址会显示跳转后的URL地址
permanent #返回301永久重定向,浏览器地址栏会显示跳转后的URL地址

实例

rewrite ^/([0-9]+).html$  /index.jsp?pageNum=$1 break;

$1 表示正则匹配符合的 第一个值。

如 请求信息匹配, 后端接口请求:

  location /StockApi {
                # 把 /stock 路径下的请求转发给真正的后端服务器
                rewrite  ^/(.*)$ /$1 break;
                proxy_pass http://127.0.0.1:8088$request_uri;
                fastcgi_buffers 8 128k;
                send_timeout 60;
                client_max_body_size     100m;
        }

/StockApi 后面所有的信息, 当成一个参数 /$1

参考链接: https://blog.csdn.net/LL845876425/article/details/100999186

在这里插入图片描述

在这里插入图片描述

域名跳转

在这里插入图片描述

rewrite ^/(.*) http://www.yueshushu.top/$1 permanent;


rewrite ^/(.*) http://www.yueshushu.top/$1 redirect;

post 请求方法跳转

在这里插入图片描述

return 307 http://www.yueshushu.top/$request_uri;

return 308 http://www.yueshushu.top/$request_uri;

try_files 匹配规则

寻找某个路径, 如果存在,则使用原路径, 如果不存在,则使用新的路径。

如 html 404 配置中, 如果路径不存在,则跳转到首页

 try_files $uri $uri/ /index.html;

如果不存在,则 找默认的图片

 try_files $uri   $uri/  /images/logo.jpg; 

配置 html 带不带均可以访问

如访问路径 , 有一个路径 /dev/md5.html, 希望访问 /dev/md5 可以请求到, /dev/md5.html 也可以请求到

可以这么配置

try_files $uri $uri/ $uri.html u r i . p h p uri.php uri.phpis_args$query_string;

location /dev {
        try_files $uri $uri/ $uri.html $uri.php$is_args$query_string;
        root /etc/nginx;
            index index.html index.htm;
        }

防盗链配置

访问 : https://www.yueshushu.top/logo.jpg

在这里插入图片描述

请求头不携带任何信息都可以访问

valid_referers none | blocked | server_names | strings …;

none, 检测 Referer 头域不存在的情况。
blocked,检测 Referer 头域的值被防火墙或者代理服务器删除或伪装的情况。这种情况该头域的值不以 “http://” 或 “https://” 开头。
server_names ,设置一个或多个 URL ,检测 Referer 头域的值是否是这些 URL 中的某一个。

            	valid_referers *.yueshushu.top www.yueshushu.top *.baidu.com *.google.com;
                if ($invalid_referer) {
                        return 403;
                }

只允许 这几个访问: *.yueshushu.top www.yueshushu.top *.baidu.com *.google.com;

注意, Referer 时, 请求值 要加上协议。

location / {
                root html;
                index  index.html index.htm;
                valid_referers *.yueshushu.top www.yueshushu.top *.baidu.com *.google.com;
                if ($invalid_referer) {
                        return 403;
                }
                try_files $uri $uri/ /index.html;
        }

再次请求时:

在这里插入图片描述

在这里插入图片描述

配置 https 443 端口访问

免费申请一个证书, 下载 nginx 版本的

在这里插入图片描述

使用到 域名.key 域名_bundle.crt 两个证书

上传到 /etc/nginx/ssl/Nginx 目录下

在这里插入图片描述

进行配置:

	server {
		listen       443 ssl;
		server_name  www.yueshushu.top;
		ssl_certificate   /etc/nginx/ssl/Nginx/1_www.yueshushu.top_bundle.crt;
		ssl_certificate_key  /etc/nginx/ssl/Nginx/2_www.yueshushu.top.key;

    	# 其它的配置信息
}

如此即可.

配置 https 和 http 均可以访问

访问 http 时,会跳转到 https 协议地址

# 将Http请求转化成Https请求
server {
  listen 80;
  server_name www.yueshushu.top;
  rewrite ^/(.*) https://$server_name$request_uri? permanent;
}

配置多个虚拟服务器

在实际业务中, 常常 有多个 前端项目, 每个项目可能存在多个分支, 可这些分支拥有着相同的请求路径, 如 都是 /StockApi , 这个时候,在同一个 server 下配置就不好了。 更不应该 复制多个 nginx ,每一个 nginx 跑一个项目。

实际上,对 单个 nginx 可以配置多个虚拟服务器, 拥有着不同的端口号, 这样就可以给不同的项目使用了。

端口号 listen 和 前端 路径 不同 alias

server {
		listen       8027;
		server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


		location /StockApi {
			# 把 /stock 路径下的请求转发给真正的后端服务器
			rewrite  ^/(.*)$ /$1 break;
			proxy_pass http://myproxy$request_uri;
			fastcgi_buffers 8 128k;
			send_timeout 60;
			client_max_body_size     100m;
		}

		location ~ ^/(images|js|css|flash|media|static)/ {
			root C:\\Users\\20481\\Downloads\\nginx-1.22.1\\staticFile;
			#过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
			expires 30d;
		}
		location /Stock {
			alias C:\\Users\\20481\\Downloads\\nginx-1.22.1\\Stock_Page;
			index page.html page.htm;
		}
        location / {
            root   html;
            index  index.html index.htm;
			# 试图访问某个文件, 如果在 就使用原文件,如果不在,就用  /index.html
			try_files $uri $uri/ /index.html;
        }
    }
	
	server {
		listen       8081;
		server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


		location /StockApi {
			# 把 /stock 路径下的请求转发给真正的后端服务器
			rewrite  ^/(.*)$ /$1 break;
			proxy_pass http://myproxy$request_uri;
			fastcgi_buffers 8 128k;
			send_timeout 60;
			client_max_body_size     100m;
		}

		location ~ ^/(images|js|css|flash|media|static)/ {
			root C:\\Users\\20481\\Downloads\\nginx-1.22.1\\staticFile;
			#过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
			expires 30d;
		}
		location /Stock {
			alias C:\\Users\\20481\\Downloads\\nginx-1.22.1\\CainiaoStock_Page;
			index page.html page.htm;
		}
        location / {
            root   html;
            index  index.html index.htm;
			# 试图访问某个文件, 如果在 就使用原文件,如果不在,就用  /index.html
			try_files $uri $uri/ /index.html;
        }
    }
	server {
		listen       8082;
		server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;


		location /StockApi {
			# 把 /stock 路径下的请求转发给真正的后端服务器
			rewrite  ^/(.*)$ /$1 break;
			proxy_pass http://myproxy$request_uri;
			fastcgi_buffers 8 128k;
			send_timeout 60;
			client_max_body_size     100m;
		}

		location ~ ^/(images|js|css|flash|media|static)/ {
			root C:\\Users\\20481\\Downloads\\nginx-1.22.1\\staticFile;
			#过期30天,静态文件不怎么更新,过期可以设大一点,如果频繁更新,则可以设置得小一点。
			expires 30d;
		}
		location /Stock {
			alias C:\\Users\\20481\\Downloads\\nginx-1.22.1\\yjlStock_Page;
			index page.html page.htm;
		}
        location / {
            root   html;
            index  index.html index.htm;
			# 试图访问某个文件, 如果在 就使用原文件,如果不在,就用  /index.html
			try_files $uri $uri/ /index.html;
        }
    }

servername匹配规则 我们需要注意的是servername匹配分先后顺序,
写在前面的匹配上就不会继续往下匹配了。

完整匹配 我们可以在同一servername中匹配多个域名 server_name vod.mmban.com www1.mmban.com;

通配符匹配 server_name *.mmban.com

通配符结束匹配 server_name vod.*;

正则匹配 server_name ~1+.mmban.com$;

跨域 cors 配置

在浏览器上当前访问的网站向另一个网站发送请求获取数据的过程就是跨域请求。

跨域是浏览器的同源策略决定的,是一个重要的浏览器安全策略,用于限制一个 origin 的文档或者它加载的脚本与另一个源的资源进行交互,它能够帮助阻隔恶意文档,减少可能被攻击的媒介,可以使用 CORS 配置解除这个限制。

关于跨域网上已经有很多解释,这里就不啰嗦,也可以直接看 MDN 的 <浏览器的同源策略> 文档进一步了解,这里就列举几个同源和不同元的例子,相信程序员都能看得懂。

# 同源的例子
http://example.com/app1/index.html  # 只是路径不同
http://example.com/app2/index.html

http://Example.com:80  # 只是大小写差异
http://example.com

# 不同源的例子
http://example.com/app1   # 协议不同
https://example.com/app2

http://example.com        # host 不同
http://www.example.com
http://myapp.example.com

http://example.com        # 端口不同
http://example.com:8080

配置跨域:

	server {
		listen       8027;
		server_name  localhost;


	  #允许跨域请求的域,* 代表所有
      add_header 'Access-Control-Allow-Origin' *;
      #允许带上cookie请求
      add_header 'Access-Control-Allow-Credentials' 'true';
      #允许请求的方法,比如 GET/POST/PUT/DELETE
      add_header 'Access-Control-Allow-Methods' *;
      #允许请求的header
      add_header 'Access-Control-Allow-Headers' *;

      # 省略配置 location 

}

参考链接: https://blog.csdn.net/qq_38011415/article/details/107095403

配置 真实的 IP 和端口

nginx 转发之后,后端获取的 IP地址等信息,是 nginx 所在服务器的 IP地址, 并不是 客户请求时的 IP地址。

    		proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-PORT $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

在具体的 location 下

	location /StockApi {
			# 把 /stock 路径下的请求转发给真正的后端服务器
			proxy_set_header Host $host:$server_port;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Real-PORT $remote_port;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

			rewrite  ^/(.*)$ /$1 break;
			proxy_pass http://myproxy$request_uri;
			fastcgi_buffers 8 128k;
			send_timeout 60;
			client_max_body_size     100m;
		}

配置成功。

配置开启 gzip

gzip on; # 默认off,是否开启gzip
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

# 上面两个开启基本就能跑起了,下面的愿意折腾就了解一下
gzip_static on;
gzip_proxied any;
gzip_vary on;
gzip_comp_level 6;
gzip_buffers 16 8k;
# gzip_min_length 1k;
gzip_http_version 1.1;

在这里插入图片描述


  1. 0-9 ↩︎

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/59916.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

20221104英语学习

今日单词&#xff1a; portable adj.轻便的&#xff0c;便携的&#xff1b;手提式的 beautiful adj.美丽的, 风和日丽的, 出色的 hunter n.猎人, 狩猎者, &#xff08;猎食其他动物的&#xff09;猎兽, 搜集某种东西的人 circle n.圆, 圈, 圆形, 圆圈 style n.样式, 风格,…

Unity 算法 之 点集中计算绘制 凸包 的简单整理

Unity 算法 之 点集中计算绘制 凸包 的简单整理 目录 Unity 算法 之 点集中计算绘制 凸包 的简单整理 一、简单介绍 二、Graham扫描法 第一种说明&#xff1a; 第二种说明&#xff1a; 三、代码&#xff08;第二种说明&#xff09; 四、参考文献 一、简单介绍 算法&…

工作上的三个境界:能做,能做好,能持续做好

某天&#xff0c;技术岗A员工抬杠管理岗B员工的工作&#xff1a;你的工作啊&#xff0c;实习生都能做&#xff0c;你的价值太小了........一顿DISS。 这样的场景&#xff0c;似曾相识否&#xff1f;这是职场中常见的一类人“杠精”的表现。 做技术的&#xff0c;往往认为管理…

MySQL8.0 OCP最新版1Z0-908认证考试题库整理-006

原题 Choose the best answer.You are having performance issues with MySQL instances. Those servers are monitored withMySQL Enterprise Monitor.Using Query Analyzer, where do you begin to look for problem queries?A) Sort the "Exec" column and check…

什么是物联网?如何保护物联网iot安全性

物联网iot:物联网&#xff08;IoT&#xff09;将生活中事物以网络进行连接&#xff0c;彼此交换信息。整个世界借由设备连接成一体。 对于消费者而言&#xff0c;这意味着您可以在大洋彼岸远程调节家中的恒温器。但是对企业而言&#xff0c;物联网不仅创造了连接客户和合作伙伴…

BBR 公平收敛

BBR 的公平收敛来自于两点&#xff1a; ProbeBW 状态加速比收敛&#xff1a;带宽越大&#xff0c;加速比越小。ProbeRTT 状态 RTT 收敛&#xff1a;inflight 越大&#xff0c;越容易让 inflight 小的测到 minrtt 而避免进入 ProbeRTT&#xff0c;inflight 越小&#xff0c;测量…

用Python代码自己写Python代码,竟如此简单

用Python代码自己写Python代码&#xff0c;竟如此简单 Python作为一门功能强大且使用灵活的编程语言&#xff0c;可以应用于各种领域&#xff0c;具有“无所不能”的特质。 Python甚至可以代替人&#xff0c;自己写Python代码。而且很简单&#xff0c;只需学会Python的基础知…

RabbitMQ学习笔记

目录 尚硅谷mq视频学习笔记 1.1. MQ 的相关概念 1.1.1. 什么是MQ 1.1.2. 为什么要用MQ 1.1.3. MQ 的分类 1.ActiveMQ 2.Kafka 3.RocketMQ 4.RabbitMQ 1.1.4. MQ 的选择 1.Kafka 2.RocketMQ 3.RabbitMQ 1.2. RabbitMQ 1.2.1. RabbitMQ 的概念 1.2.2. 四大核心概念…

7.7网络(二)

接上篇&#xff1a;7.7 网络&#xff08;一&#xff09;_龙赤子的博客-CSDN博客 目录 三 操作系统涉及的网络内容 1 网络栈 2 协议 3 应用 三 操作系统涉及的网络内容 1 网络栈 这里我们重点讨论操作系统里面的网络。这部分在整个网络架构中&#xff0c;属于端的技术。对于端来…

分布式锁-全面详解(学习总结---从入门到深化)

目录 分布式锁概述 为什么需要分布式锁 什么是分布式锁 分布式锁的特点 分布式锁问题_业务介绍 案列介绍 技术选型 创建表 创建订单表 创建商品表 创建订单商品关联表 分布式锁问题_创建SpringBoot项目 引入依赖 修改配置文件 编写主启动类 代码生成 编写创建订单接…

(附源码)node.js电商管理系统 毕业设计 251001

node.js电商管理系统 摘 要 随着科学技术的飞速发展&#xff0c;社会的方方面面、各行各业都在努力与现代的先进技术接轨&#xff0c;通过科技手段来提高自身的优势&#xff0c;电商管理系统当然也不能排除在外。电商管理系统 是以实际运用为开发背景&#xff0c;运用软件工程开…

【数据结构与算法】拓扑排序与关键路径

&#x1f525; 本文由 程序喵正在路上 原创&#xff0c;CSDN首发&#xff01; &#x1f496; 系列专栏&#xff1a;数据结构与算法 &#x1f320; 首发时间&#xff1a;2022年12月4日 &#x1f98b; 欢迎关注&#x1f5b1;点赞&#x1f44d;收藏&#x1f31f;留言&#x1f43e;…

【C++智能指针】智能指针的发展和循环引用的原理和解决

目录 1.RAIl&#xff08;智能指针的雏形&#xff09; 2.拷贝导致的问题以及智能指针发展历史 2.1拷贝的问题&#xff08;资源被析构两次&#xff09; 2.2auto_ptr(资源权转移&#xff0c;不建议使用) 2.3unique_ptr(防拷贝&#xff0c;在不需要拷贝的情况下使用) 2.4share…

【vue】vue-count-to(数字滚动)插件:

文章目录一、效果&#xff1a;二、使用&#xff1a;【1】安装插件【2】案例三、Options四、Functions一、效果&#xff1a; 二、使用&#xff1a; 官方文档&#xff1a; github地址——https://github.com/PanJiaChen/vue-countTo npm地址——https://www.npmjs.com/package/…

在本地PC运行 Stable Diffusion 2.0

Stable Diffusion 2.0在前几天已经发布了&#xff0c;新版本在上一个版本的基础上进行了许多改进。OpenCLIP中新的深度检测和更好的文本到图像模型是主要的改进之一。 有很多的文章介绍了Stable Diffusion 2.0的改进&#xff0c;所以我们就不多介绍了&#xff0c;这里我们将介…

30分钟部署一个kubernetes集群【1.17】

作者:李振良 kubeadm是官方社区推出的一个用于快速部署kubernetes集群的工具。 这个工具能通过两条指令完成一个kubernetes集群的部署: # 创建一个 Master 节点 $ kubeadm init# 将一个 Node 节点加入到当前集群中 $ kubeadm join <Master节点的IP和端口 >1. 安装要求…

.m3u8.sqlite文件转mp4,m3u8.sqlite文件转视频工具(开源免费)

文章目录一、预先准备1. 前提2. 主要思路3. 准备工具二、视频转换实战2.1. 软件下载2.2. TS转MP4工具2.3. 操作流程一、预先准备 1. 前提 如果已经买了课程&#xff0c;是可以下载的&#xff0c;并且腾讯课堂APP里就有下载功能。 2. 主要思路 在APP上下载视频缓存到手机本地…

postgres源码解析41 btree索引文件的创建--1

上述小节讲解了索引文件的物理创建&#xff0c;本篇讲解btree索引元组填充至索引文件的操作。先从数据结构入手&#xff0c;后深入执行流程。 postgres源码解析37 表创建执行全流程梳理–1 postgres源码解析37 表创建执行全流程梳理–2 postgres源码解析37 表创建执行全流程梳理…

详解设计模式:责任链模式

责任链模式&#xff08;Chain of Responsibility Pattern&#xff09;也被称为职责链模式&#xff0c;是在 GoF 23 种设计模式中定义了的行为型模式。 责任链模式 是将链中的每一个节点看作是一个对象&#xff0c;每个节点处理的请求不同&#xff0c;且内部自动维护一个下一节点…

降温了好冷,总结下11月

1、这两天广东气温骤降&#xff0c;出门必须加外套了&#xff0c;emmm&#xff0c;不想出门&#xff0c;各位宝宝注意保暖吖&#xff0c;别感冒了。2、这边疫情开始放开了&#xff0c;备好感冒药&#xff0c;锻炼身体&#xff0c;做好预防&#xff0c;靠自己了。3、11月过的真快…