Nginx服务优化配置
1、expires缓存模块

具体配置可参考官方文档 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)

配置压缩模块
[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服务优化配置的更多相关文章
- Nginx服务优化及优化深入(配置网页缓存时间、日志切割、防盗链等等)
原文:https://blog.51cto.com/11134648/2134389 默认的Nginx安装参数只能提供最基本的服务,还需要调整如网页缓存时间.连接超时.网页压缩等相应参数,才能发挥出服 ...
- nginx + SSL优化配置
nginx + SSL优化配置: #http段添加如下配置项: http { ssl_prefer_server_ciphers on; #设置协商加密算法时,优先使用我们服务端的加密套件,而不是客户 ...
- 【实战分享】又拍云 OpenResty / Nginx 服务优化实践
2018 年 11 月 17 日,由 OpenResty 主办的 OpenResty Con 2018 在杭州举行.本次 OpenResty Con 的主题涉及 OpenResty 的新开源特性.业界 ...
- Nginx服务优化详解
Nginx服务优化详解 1.隐藏Nginx版本信息 编辑主配置文件nginx.conf,在http标签中添加代码 server_tokens off;来隐藏软件版本号. 2.更改Nginx服务启动的默 ...
- nginx服务优化大全
第18章 nginx服务优化 18.1 复习以前的nginx知识 18.1.1 复习nginx编译安装的3部曲 ./configure 配置(开启/关闭功能),指定安装目录 make ...
- 企业级Web Nginx 服务优化
企业级Web Nginx 服务优化 http://blog.51cto.com/search/result?q=%E4%BC%81%E4%B8%9A%E7%BA%A7Web+Nginx+%E6%9C% ...
- Nginx服务优化
1.1Nginx.conf配置文件基本参数优化 1.1.1 隐藏nginx header内版本号信息 一些特定的系统及服务漏洞一般都和特定的软件及版本号有关,我们应尽量隐藏服务器的敏感信息(软件名称 ...
- 企业级web nginx服务优化
1.1)隐藏nginx header 内版本号信息 [root@aliyun ~]# vi /application/nginx/conf/nginx.conf http{ …… server_tok ...
- Nginx服务安装配置
1.Nginx介绍 Nginx是一个高性能的HTTP和反向代理服务器,由俄罗斯人开发的,第一个版本发布于2004年10月4日.Nginx由于出色的性能,在世界范围内受到了越来越多人的关注,其特点是占有 ...
随机推荐
- Hudson和Jenkins的关系
Jenkins is an open source continuous integration tool written in Java. The project was forked from H ...
- c语言-单链表(一)
定义节点: typedef struct Node { int data; Node* pNext; }NODE, *PNODE; 细节说明,PNode 就代表struct Node* ,上面的表单是 ...
- SQL基础(3)
SQL FULL JOIN (1)SQL FULL JOIN关键字 只要其中某个表存在匹配,FULL JOIN 关键字就会返回行. (2)语法 SELECT column_name(s) FROM t ...
- 火星坐标、百度坐标、WGS84坐标转换代码(JS)
JS版本源码 /** * Created by Wandergis on 2015/7/8. * 提供了百度坐标(BD09).国测局坐标(火星坐标,GCJ02).和WGS84坐标系之间的转换 */ / ...
- HTML5实用知识点
本文讲解HTML5实用知识点 新增的表单type Canvas使用 SVG使用 Audio使用 Video使用 网页缓存 文件缓存 后台worker Server-Sent Events 定位 拖放功 ...
- jsonp实现跨域请求的本质demo[无法发送post请求]
views.py def get_data(request): return HttpResponse("机密数据") urls.py urlpatterns = [ url(r' ...
- Oracle的REGEXP_REPLACE函数简单用法
转载:http://blog.csdn.net/itmyhome1990/article/details/50380718
- python request (1) 环境
环境准备 requests httpbin virtualenv pip python 安装 #mkdir /home/requests #yum install -y python-pip ...
- C语言学习笔记--函数与指针
1. 函数类型 (1)C 语言中的函数有自己特定的类型,这个类型由返回值.参数类型和参数个数共同决定.如 int add(int i,int j)的类型为 int(int,int). (2)C 语言中 ...
- 使用NDK编译 libyuv <转>
官方源码:http://code.google.com/p/libyuv/简介: libyuv is an open source project that includes YUV scaling ...