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;
         } 
的区别
相关推荐
物联网老王1 小时前
Ubuntu Linux Cursor 安装与使用一
linux·运维·ubuntu
艾伦_耶格宇2 小时前
【ACP】阿里云云计算高级运维工程师--ACP
运维·阿里云·云计算
一位摩羯座DBA3 小时前
Redhat&Centos挂载镜像
linux·运维·centos
charlee443 小时前
nginx部署发布Vite项目
nginx·性能优化·https·部署·vite
cui_win4 小时前
【网络】Linux 内核优化实战 - net.core.flow_limit_table_len
linux·运维·网络
风清再凯4 小时前
自动化工具ansible,以及playbook剧本
运维·自动化·ansible
深圳安锐科技有限公司4 小时前
深圳安锐科技发布国内首款4G 索力仪!让斜拉桥索力自动化监测更精准高效
运维·安全·自动化·自动化监测·人工监测·桥梁监测·索力监测
猫头虎4 小时前
猫头虎 AI工具分享:一个网页抓取、结构化数据提取、网页爬取、浏览器自动化操作工具:Hyperbrowser MCP
运维·人工智能·gpt·开源·自动化·文心一言·ai编程
CRMEB定制开发5 小时前
【实战】CRMEB Pro 企业版安装教程(附 Nginx 反向代理配置 + 常见问题解决)
nginx·商城系统·微信商城·crmeb
cocologin6 小时前
RIP 技术深度解析
运维·网络·网络协议