nginx 动静分离、gzip压缩、负载均衡、root/alias

javascript 复制代码
location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
    access_log        off;
    log_not_found     off;
    expires           30d;
    root  static;
}  
比如我的 host是 gyk.com 当访问呢 gyk.com/a/b/c.png ,
Nginx 会在 static/a/b/ 目录下查找 c.png 文件。


通常我们期望 URL 路径和文件系统路径是匹配的。

gzip:

javascript 复制代码
在 http 块中,添加以下配置:

gzip on;
gzip_disable "msie6";

gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;



gzip on; 启用 Gzip 压缩。
gzip_disable "msie6"; 禁用对 IE6 的 Gzip 压缩,因为 IE6 不支持 Gzip 压缩。
gzip_vary on; 启用 Vary HTTP 头,这可以帮助代理服务器了解原始服务器是否已经对内容进行了 Gzip 压缩。
gzip_proxied any; 对所有经过代理的请求启用 Gzip 压缩。
gzip_comp_level 6; 设置 Gzip 压缩级别,范围是 1(最低,压缩速度最快)到 9(最高,压缩效果最好)。
gzip_buffers 16 8k; 设置用于压缩的缓冲区数量和大小。
gzip_http_version 1.1; 设置启用 Gzip 压缩的 HTTP 版本。
gzip_types ...; 设置需要进行 Gzip 压缩的 MIME 类型。
保存并关闭配置文件。

重新加载或重启 Nginx 以应用新的配置。你可以使用以下命令来重新加载 Nginx 配置
sudo service nginx reload

负载均衡:

root 和 alias

javascript 复制代码
location /cn {
            alias   html/en;
            index  index.html index.htm;
         }  
和 
location /cn {
            root    html/en;
            index  index.html index.htm;
         } 
的区别
相关推荐
AKAMAI5 小时前
你的源服务器可能是你做出的最昂贵决定
运维·人工智能·云计算
Dxy12393102165 小时前
Linux 编译安装 Python 3.12.10(多版本共存,不破坏系统Python)
linux·运维·python
技术深耕者6 小时前
AI Agent从演示到生产:企业进入“自动化层”时代
运维·人工智能·自动化
w67820078 小时前
Prisma不能优雅的支持DTO,试试Vona ORM吧
linux·运维·ubuntu
APItesterCris8 小时前
Open Claw 实战教程:5 分钟搭建京东商品自动化监控与数据分析系统
大数据·运维·数据库·数据仓库·自动化
杨某不才10 小时前
如何能让Linux服务器对shell 终端 + sftp 文件传输长期保活
linux·运维·服务器
三言老师11 小时前
文本工具组合统计服务器日志数据
linux·运维·服务器
m0_7436975911 小时前
DNS服务器
运维·服务器
yj_xqj13 小时前
Docker 基础应用与介绍
运维·docker·容器
happymagic14 小时前
vmware workstation Pro 虚拟机设定启停的时间段
运维·服务器·windows