Nginx服务优化配置

时间:2022-09-09 16:40:32

1、expires缓存模块

Nginx服务优化配置

具体配置可参考官方文档 http://nginx.org/en/docs/http/ngx_http_headers_module.html#expires

[root@cairui conf]# cat nginx.conf | egrep -v "#|^$"
user nginx;
worker_processes ;
events {
worker_connections ;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout ;
server {
listen ;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|html|htm|css)$ {
log_not_found off;
expires 7d ;
access_log off;
proxy_store on;
proxy_store_access user:rw group:rw all:rw;
}
error_page /50x.html;
location = /50x.html {
root html;
}
}
}
[root@cairui conf]# curl -I http://120.25.255.87/1.jpg
HTTP/1.1 OK
Server: nginx/1.13.
Date: Mon, Mar :: GMT
Content-Type: image/jpeg
Content-Length:
Last-Modified: Wed, Nov :: GMT
Connection: keep-alive
ETag: "5a1e6ce7-bdb1"
Expires: Mon, 12 Mar 2018 04:08:41 GMT
Cache-Control: max-age=
Accept-Ranges: bytes

2、Nginx压缩模块(gzip)

Nginx服务优化配置

配置压缩模块
[root@localhost vhost]# vi www.vhosts
server {
listen ;
server_name 192.168.1.3;
location / {
root /web/www;
index index.html index.htm;
access_log /application/nginx/log/access_www.log commonlog;
}
location ~ .*\.(gif|jpg|jpge|png|bmp|swf)$
{
expires 3560d;
root /web/www;
}
location ~ .*\.(js|css)?$
{
expires 30d;
root /web/www;
}
gzip on; #开启压缩功能
gzip_min_length 1k; #设置允许压缩页面的最小字节数
gzip_buffers 16k;
gzip_http_version 1.0;
gzip_comp_level ;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
}
检查语法、重启服务
[root@localhost vhost]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.10./conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.10./conf/nginx.conf test is successful
[root@localhost vhost]# /application/nginx/sbin/nginx -s reload
[root@localhost vhost]# cd /web/www/
[root@localhost www]# ll
total
-rw-r--r--. root root Sep : index.html
-rw-r--r--. root root Sep : mysql.jpg
[root@localhost www]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring .js...
% KB KB/s :: Errors
?[root@localhost www]# ll
total
-rw-r--r--. root root Sep : .js
-rw-r--r--. root root Sep : index.html
-rw-r--r--. root root Sep : mysql.jpg
客户端访问 http://192.168.1.3:8001/1.js
[root@localhost www]# curl -I http://192.168.1.3:8001/1.js
HTTP/1.1 OK
Server: nginx/1.10.
Date: Tue, Sep :: GMT
Content-Type: application/javascript
Content-Length:
Last-Modified: Tue, Sep :: GMT
Connection: keep-alive
ETag: "57e9d41f-abca"
Expires: Thu, Oct :: GMT
Cache-Control: max-age=
Accept-Ranges: bytes

Nginx服务优化配置的更多相关文章

  1. Nginx服务优化及优化深入(配置网页缓存时间、日志切割、防盗链等等)

    原文:https://blog.51cto.com/11134648/2134389 默认的Nginx安装参数只能提供最基本的服务,还需要调整如网页缓存时间.连接超时.网页压缩等相应参数,才能发挥出服 ...

  2. nginx + SSL优化配置

    nginx + SSL优化配置: #http段添加如下配置项: http { ssl_prefer_server_ciphers on; #设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户 ...

  3. 【实战分享】又拍云 OpenResty / Nginx 服务优化实践

    2018 年 11 月 17 日,由 OpenResty 主办的 OpenResty Con 2018 在杭州举行.本次 OpenResty Con 的主题涉及 OpenResty 的新开源特性.业界 ...

  4. Nginx服务优化详解

    Nginx服务优化详解 1.隐藏Nginx版本信息 编辑主配置文件nginx.conf,在http标签中添加代码 server_tokens off;来隐藏软件版本号. 2.更改Nginx服务启动的默 ...

  5. 企业级Web Nginx 服务优化

    企业级Web Nginx 服务优化 http://blog.51cto.com/search/result?q=%E4%BC%81%E4%B8%9A%E7%BA%A7Web+Nginx+%E6%9C% ...

  6. Nginx服务优化

    1.1Nginx.conf配置文件基本参数优化 1.1.1  隐藏nginx header内版本号信息 一些特定的系统及服务漏洞一般都和特定的软件及版本号有关,我们应尽量隐藏服务器的敏感信息(软件名称 ...

  7. 企业级web nginx服务优化

    1.1)隐藏nginx header 内版本号信息 [root@aliyun ~]# vi /application/nginx/conf/nginx.conf http{ …… server_tok ...

  8. Nginx服务安装配置

    1.Nginx介绍 Nginx是一个高性能的HTTP和反向代理服务器,由俄罗斯人开发的,第一个版本发布于2004年10月4日.Nginx由于出色的性能,在世界范围内受到了越来越多人的关注,其特点是占有 ...

  9. zookeeper分布式锁和服务优化配置

    转自:https://www.jianshu.com/p/02eeaee4357f?utm_campaign=maleskine&utm_content=note&utm_medium ...

随机推荐

  1. NPOI的版本查看

    从github上clone源代码 git clone https://github.com/tonyqus/npoi.git 下载的版本库中,有一个名为Release Notes.txt的文件,在这个 ...

  2. linux free

    在Linux下查看内存我们一般用command free [root@nonamelinux ~]# free total           used           free        s ...

  3. SQL数据库置疑修复

    SQL数据库置疑修复 首先分析数据库置疑的原因,查明原因分析数据库置疑修复的方法,解决置疑后,考虑数据库置疑的预防方案.   数据库置疑产生的原因: 1.sql所在分区空间是否够?数据库文件大小是否达 ...

  4. Vuforia的图像识别之后的服务器下载与ARKit的兼容性解决

    2017.12.12 遇到的问题: Could not produce class with ID 75 直接关闭unity里面的Strip engine code,解决下载ab时的崩溃问题 *Str ...

  5. scrapy系列(一)——Python 爬虫框架 Scrapy1.2 Windows 安装教程

    scrapy作为一个成熟的爬虫框架,网上有大量的相关教程供大家选择,尤其是关于其的安装步骤更是丰富的很.在这里我想记录下自己的相关经验,希望能给大家带来点帮助. 在scrapy0.24版之前,安装sc ...

  6. cxListView和dbgrid联动

    procedure TForm1.FormCreate(Sender: TObject); begin ClientDataSet1.First; while not ClientDataSet1.E ...

  7. Python+Requests接口测试教程(2):requests

    开讲前,告诉大家requests有他自己的官方文档:http://cn.python-requests.org/zh_CN/latest/ 2.1 发get请求 前言requests模块,也就是老污龟 ...

  8. 算法day01

  9. MSSQL移除字符串两边的指定字符

    移除字符串左边的字符: CREATE FUNCTION [dbo].[RemoveLeftChar] ( @Expression varchar(max), @char varchar(4))RETU ...

  10. java session特性

    1.当前浏览器不关闭 则一直有效 servlet就能取到值(未设置过期时间情况下 或者在过期的时间范围内)  算成一次会话 再次会话内多个请求都能获得session 2.session保存在服务端,通 ...