1.Nginx简介
常见的web服务器:Apache Lighttpd Tomcat IBMWebSphere MicrosoftIIS Nginx
Nginx的优点:
高并发连接
内存消耗小
配置文件简单
支持Rewrite重写规则
内置健康检查功能
节省带宽,支持gzip压缩,可以添加浏览器本地缓冲的Header头
稳定性高
支持热部署,就是在不间断服务的情况下,对软件版本进行升级
2.Nginx服务器的安装和配置
安装Nginx 安装需要GCC编译器和autoconf和automake工具,GCC可用于C C++ Objective-C Fortran Java等的编译,autoconf和automake用于自动创建功能完善的Makefile 在CentOS系统下,可以通过yum命令安装GCC编译器及相关工具 yum -y install gcc gcc-c++ autoconf automake Nginx的一些模块需要其他第三方库的支持,例如gzip模块需要zlib库,rewrite库需要pcre库,ssl功能需要openssl库等,同样在CentOS系统下,可以使用yum命令安装或下载源码包编译安装这些模块依赖的库: yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel ******************************************************************** windows下下载和安装较简单略过 windows下使用以下dos命令控制Nginx进程 nginx -s [ stop | quit | reopen | reload ] ******************************************************************** Linux下安装Nginx tar -zxvf nginx-0.x.xx.tar.gz cd nginx-0.x.xx ./configure make sudo make install ******************************************************************** 执行./configure --help的结果 [root@localhost nginx-1.2.6]# ./configure --help --help print this message --prefix=PATH set installation prefix --sbin-path=PATH set nginx binary pathname --conf-path=PATH set nginx.conf pathname --error-log-path=PATH set error log pathname --pid-path=PATH set nginx.pid pathname --lock-path=PATH set nginx.lock pathname --user=USER set non-privileged user for worker processes --group=GROUP set non-privileged group for worker processes --builddir=DIR set build directory --with-rtsig_module enable rtsig module --with-select_module enable select module --without-select_module disable select module --with-poll_module enable poll module --without-poll_module disable poll module --with-file-aio enable file AIO support --with-ipv6 enable IPv6 support --with-http_ssl_module enable ngx_http_ssl_module --with-http_realip_module enable ngx_http_realip_module --with-http_addition_module enable ngx_http_addition_module --with-http_xslt_module enable ngx_http_xslt_module --with-http_image_filter_module enable ngx_http_image_filter_module --with-http_geoip_module enable ngx_http_geoip_module --with-http_sub_module enable ngx_http_sub_module --with-http_dav_module enable ngx_http_dav_module --with-http_flv_module enable ngx_http_flv_module --with-http_mp4_module enable ngx_http_mp4_module --with-http_gzip_static_module enable ngx_http_gzip_static_module --with-http_random_index_module enable ngx_http_random_index_module --with-http_secure_link_module enable ngx_http_secure_link_module --with-http_degradation_module enable ngx_http_degradation_module --with-http_stub_status_module enable ngx_http_stub_status_module --without-http_charset_module disable ngx_http_charset_module --without-http_gzip_module disable ngx_http_gzip_module --without-http_ssi_module disable ngx_http_ssi_module --without-http_userid_module disable ngx_http_userid_module --without-http_access_module disable ngx_http_access_module --without-http_auth_basic_module disable ngx_http_auth_basic_module --without-http_autoindex_module disable ngx_http_autoindex_module --without-http_geo_module disable ngx_http_geo_module --without-http_map_module disable ngx_http_map_module --without-http_split_clients_module disable ngx_http_split_clients_module --without-http_referer_module disable ngx_http_referer_module --without-http_rewrite_module disable ngx_http_rewrite_module --without-http_proxy_module disable ngx_http_proxy_module --without-http_fastcgi_module disable ngx_http_fastcgi_module --without-http_uwsgi_module disable ngx_http_uwsgi_module --without-http_scgi_module disable ngx_http_scgi_module --without-http_memcached_module disable ngx_http_memcached_module --without-http_limit_conn_module disable ngx_http_limit_conn_module --without-http_limit_req_module disable ngx_http_limit_req_module --without-http_empty_gif_module disable ngx_http_empty_gif_module --without-http_browser_module disable ngx_http_browser_module --without-http_upstream_ip_hash_module disable ngx_http_upstream_ip_hash_module --without-http_upstream_least_conn_module disable ngx_http_upstream_least_conn_module --without-http_upstream_keepalive_module disable ngx_http_upstream_keepalive_module --with-http_perl_module enable ngx_http_perl_module --with-perl_modules_path=PATH set Perl modules path --with-perl=PATH set perl binary pathname --http-log-path=PATH set http access log pathname --http-client-body-temp-path=PATH set path to store http client request body temporary files --http-proxy-temp-path=PATH set path to store http proxy temporary files --http-fastcgi-temp-path=PATH set path to store http fastcgi temporary files --http-uwsgi-temp-path=PATH set path to store http uwsgi temporary files --http-scgi-temp-path=PATH set path to store http scgi temporary files --without-http disable HTTP server --without-http-cache disable HTTP cache --with-mail enable POP3/IMAP4/SMTP proxy module --with-mail_ssl_module enable ngx_mail_ssl_module --without-mail_pop3_module disable ngx_mail_pop3_module --without-mail_imap_module disable ngx_mail_imap_module --without-mail_smtp_module disable ngx_mail_smtp_module --with-google_perftools_module enable ngx_google_perftools_module --with-cpp_test_module enable ngx_cpp_test_module --add-module=PATH enable an external module --with-cc=PATH set C compiler pathname --with-cpp=PATH set C preprocessor pathname --with-cc-opt=OPTIONS set additional C compiler options --with-ld-opt=OPTIONS set additional linker options --with-cpu-opt=CPU build for the specified CPU, valid values: pentium, pentiumpro, pentium3, pentium4, athlon, opteron, sparc32, sparc64, ppc64 --without-pcre disable PCRE library usage --with-pcre force PCRE library usage --with-pcre=DIR set path to PCRE library sources --with-pcre-opt=OPTIONS set additional build options for PCRE --with-pcre-jit build PCRE with JIT compilation support --with-md5=DIR set path to md5 library sources --with-md5-opt=OPTIONS set additional build options for md5 --with-md5-asm use md5 assembler sources --with-sha1=DIR set path to sha1 library sources --with-sha1-opt=OPTIONS set additional build options for sha1 --with-sha1-asm use sha1 assembler sources --with-zlib=DIR set path to zlib library sources --with-zlib-opt=OPTIONS set additional build options for zlib --with-zlib-asm=CPU use zlib assembler sources optimized for the specified CPU, valid values: pentium, pentiumpro --with-libatomic force libatomic_ops library usage --with-libatomic=DIR set path to libatomic_ops library sources --with-openssl=DIR set path to OpenSSL library sources --with-openssl-opt=OPTIONS set additional build options for OpenSSL --with-debug enable debug logging ******************************************************************************* Nginx的启动 sbin-path/nginx -c /path/to/nginx.conf -c 制定配置文件的路径 ,如果不加 -c 参数,Nginx会默认加载器安装目录的conf子目录中的nginx.conf ******************************************************************************* Nginx的停止 使用ps -ef | grep nginx查看Nginx的主进程号 kill -信号类型 `/path/to/nginx.pid` 1> 从容停止Nginx kill -QUIT Nginx主进程 或 kill -QUIT `/path/to/nginx.pid` 2>快速停止Nginx kill -TERM Nginx主进程 或 kill -TERM `/path/to/nginx.pid` 或 kill -INT Nginx主进程号 或 kill -INT `/path/to/nginx.pid` 3>强制停止所有Nginx进程 pkill -9 nginx ****************************************************************************** Nginx的平滑重启 第一步判断配置文件语法是否正确 /path/to/nginx -t -c /paht/to/nginx.conf 第二步可以平滑重启Nginx了 kill -HUP Nginx主进程号 kill -HUP `/path/to/nginx.pid` ***************************************************************************** Nginx的信号控制 TERM,INT 快速关闭 QUIT 从容关闭 WINCH 从容关闭工作进程 HUP 平滑重启,重新加载配置文件 USR1 重新打开日志文件,在切割日志是用途大 USR2平滑升级可执行程序 **************************************************************************** Nginx平滑升级(热部署) 1>使用新的可执行程序替换旧的可执行程序,对于编译安装的Nginx,可以将新版本编译安装到旧版本的Nginx安装路径中.替换之前,最好备份一下旧的可执行文件 2>发送一下命令 kill -USR2 旧版本的nginx的主进程号 3>旧版本Nginx的主进程将重命名它的.pid文件为.oldpid,然后执行新版本的nginx可执行程序,依次启动新的主进程和新的工作进程 kill -USR2 之前 root 3092 1 0 16:13 ? 00:00:00 nginx: master process /usr/local/nginx-1.0.15/sbin/nginx nginx 3093 3092 0 16:13 ? 00:00:00 nginx: worker process root 5367 2871 0 16:17 pts/0 00:00:00 grep nginx kill -USR2 旧版本进程号3092 root 3092 1 0 16:13 ? 00:00:00 nginx: master process /usr/local/nginx-1.0.15/sbin/nginx nginx 3093 3092 0 16:13 ? 00:00:00 nginx: worker process root 5372 3092 0 16:19 ? 00:00:00 nginx: master process /usr/local/nginx-1.0.15/sbin/nginx nginx 5373 5372 0 16:19 ? 00:00:00 nginx: worker process root 5375 2871 0 16:19 pts/0 00:00:00 grep nginx 4>此时,新旧版本的Nginx示例会同时进行,共同处理输入的请求,发送kill -WINCH 旧版本的nginx主进程号可以逐步停止旧版本的Nginx实例 5>一段时间后,旧的工作进程处理了所有已连接的请求后退出,仅有新的工作进程处理输入的请求 kill -WINCH 旧版本进程号3092 root 3092 1 0 16:13 ? 00:00:00 nginx: master process /usr/local/nginx-1.0.15/sbin/nginx root 5372 3092 0 16:19 ? 00:00:00 nginx: master process /usr/local/nginx-1.0.15/sbin/nginx nginx 5373 5372 0 16:19 ? 00:00:00 nginx: worker process root 5389 2871 0 16:23 pts/0 00:00:00 grep nginx 6> kill -HUP 旧的主进程号: nginx将在不重载配置文件的情况下启动它的工作进程 kill -QUIT 新的主进程号:从容关闭其工作进程 kill -TERM 新的主进程号:强制退出
3.Nginx的基本配置与优化
nginx.conf的配置文件结构主要由以下几部分构成:
.......
events
{
.......
}
http
{
........
server
{
.........
}
server
{
.........
}
...............
}
***************************************************************************
Nginx的虚拟主机配置
以下是一个最简化的虚拟主机配置代码:
http{
server{
listen 80 default;
server_name _*;
access_log logs/default.access.log combined;
location / {
index index.html;
root /data0/htdocs/htdocs;
}
}
}
基于ip的虚拟主机
/sbin/ifconfig eth0:1 192.168.8.43 broadcast 192.168.0.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.8.43 dev eth0:1
/sbin/ifconfig eth0:2 192.168.8.44 broadcast 192.168.0.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.8.44 dev eth0:2
这时eth0网卡设备上绑定了两个IP别名
通过ifconfig和route配置的IP别名在服务器重启后会消失,可以将这两条命令添加到/etc/rc.local文件中,让系统开机时自动运行
然后再Nginx.conf中,分别对三个IP配置三个纯静态HTML支持的虚拟主机如下:
基于ip地址的虚拟主机配置
http{
#第一个虚拟机
server
{
#监听的ip和端口
listen 192.168.182.128:80;
#主机名称
server_name 192.168.182.128;
#访问日志文件存放路径
access_log logs/server1.access.log combined;
location /
{
#默认首页文件,顺序从左到右,如果找不到index.html文件,则查找index.htm文件作为首页文件
index index.html index.html
#HTML网页存放的目录
root /data/0/htdocs/server1;
}
}
#第二个虚拟机
server
{
#监听的ip和端口
listen 192.168.182.129:80;
#主机名称
server_name 192.168.182.129;
#访问日志文件的存放路径
access_log logs/server2.access.log combined;
location /
{
#默认首页
index index.html index.htm;
#HTML网页存放的目录
root /data0/htdocs/server2;
}
}
#第三个虚拟机
server
{
#监听的ip和端口
listen 192.168.182.130:80;
#主机名称
server_name 192.168.182.130;
#访问日志文件的存放路径
access_log logs/server3.access.log combined;
location /
{
#默认首页
index index.html index.htm;
#HTML网页存放的目录
root /data0/htdocs/server3;
}
}
}
*************************************************************************************************
基于域名的虚拟主机配置
http
{
#第一个虚拟主机
server
{
#监听的端口
listen 80;
#主机名称
server_name aaa.domain.com;
#访问日志文件存放路径
access_log logs/aaa.domain.com.access.log combined;
location /
{
index index.html index.htm;
root /data0/htdocs/aaa.domain.com;
}
}
#第二个虚拟机
server
{
listen 80;
server_name bbb.otherdomain.com;
access_log logs/bbb.otherdomain.com.access.log combined;
location /
{
index index.html index.htm;
root /data0/htdocs/bbb.otherdomain.com;
}
}
#第三个虚拟主机
server
{
listen 80;
server_name www.domain.com domain.com *.domain.com;
access_log logs/bbb.domain.com.access.log combined;
location /
{
index index.html index.htm;
root /data0/htdocs/domain.com;
}
}
}
****************************************************************************************************
Nginx的日志文件配置与切割
access_log用于指定日志文件的存放路径 格式 和缓存大小
log_format用来设置日志的格式
log_format name format [format ...]
name表示定义的格式名称,format表示定义的格式,log_format有一个默认的,无须设置的combined日志格式设置,相当于Apache的combined日志格式
log_format combined '$remote_addr - $remote_user[$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
log_format mylogformat '$http_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log path [format [buffer=size | off]]
1>access_log off; 表示不想记录日志
2>access_log /data1/logs/filename.log;
或者 access_log /data1/logs/filename.log combined
3>access_log /data1/log/access.log mylogformat buffer=32k;
4>Nginx0.7.4之后的版本中access_log指令中的日志文件路径可以包含变量
access_log /data1/logs/$server_name.log combined
***如果文件路径含有变量有一下限制
1.Nginx进程设置的用户和组必须有对该路径创建文件的权限
2.缓冲不会被使用
3.对每一条日志记录,日志文件都将先打开文件,再写入日志记录,然后关闭,为提高性能,须要使用open_log_file_cache指令设置经常被使用的日志文件描述符缓存,语法如下:
open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time] | off
默认为off
max : 设置缓存中最大文件描述符数量
inactive: 设置一个时间,如果设置的时间内没有使用此文件描述符,默认10s
min_uses:在参数inactive指定的时间范围内,如果日志文件超过使用的次数,将将该日志文件的描述符计入缓存,默认次数为1.
valid:设置多长时间检查一次,看一看变量指定的日志文件路径是否仍然存在.默认为60秒
open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m;
*********************************************************************************************
Nginx日志文件的切割
Nginx不支持像Apache一样使用cronolog来轮转日志,但可以使用kill -USR1实现日志文件的切割
mv /data1/logs/access.log /data1/logs/20090318.log
kill -USR1 Nginx主进程
可以借助crontab每天定时切割日志
vi /usr/local/nginx/sbin/cut_nginx_log.sh
cut_nginx_log.sh内容如下:
============================================================
#!/bin/bash
#这个脚本在每天的00:00运行
#Nginx日志文件的存放路径
logs_path="/data1/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}www.juzihc.com.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/juzihc_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
============================
chmod +x /usr/loca/nginx/sbin/cut_nginx_log.sh
crontab -e
=============================================================
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
=============================
***********************************************************************************************************
Nginx的压缩输出配置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
Nginx的自动列目录配置
前提条件在当前目录下不存在用index指令设置的默认首页设置
location /
{
autoindex on;
}
atuoindex_exact_size [on | off] 设置索引文件大小的单位(B KB MB或GB)
autoindex_localtime [on | off] 开启以本地时间来显示文件时间的功能默认为关
Nginx的浏览器本地缓存设置
.......
events
{
.......
}
http
{
........
server
{
.........
}
server
{
.........
}
...............
}
***************************************************************************
Nginx的虚拟主机配置
以下是一个最简化的虚拟主机配置代码:
http{
server{
listen 80 default;
server_name _*;
access_log logs/default.access.log combined;
location / {
index index.html;
root /data0/htdocs/htdocs;
}
}
}
基于ip的虚拟主机
/sbin/ifconfig eth0:1 192.168.8.43 broadcast 192.168.0.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.8.43 dev eth0:1
/sbin/ifconfig eth0:2 192.168.8.44 broadcast 192.168.0.255 netmask 255.255.255.0 up
/sbin/route add -host 192.168.8.44 dev eth0:2
这时eth0网卡设备上绑定了两个IP别名
通过ifconfig和route配置的IP别名在服务器重启后会消失,可以将这两条命令添加到/etc/rc.local文件中,让系统开机时自动运行
然后再Nginx.conf中,分别对三个IP配置三个纯静态HTML支持的虚拟主机如下:
基于ip地址的虚拟主机配置
http{
#第一个虚拟机
server
{
#监听的ip和端口
listen 192.168.182.128:80;
#主机名称
server_name 192.168.182.128;
#访问日志文件存放路径
access_log logs/server1.access.log combined;
location /
{
#默认首页文件,顺序从左到右,如果找不到index.html文件,则查找index.htm文件作为首页文件
index index.html index.html
#HTML网页存放的目录
root /data/0/htdocs/server1;
}
}
#第二个虚拟机
server
{
#监听的ip和端口
listen 192.168.182.129:80;
#主机名称
server_name 192.168.182.129;
#访问日志文件的存放路径
access_log logs/server2.access.log combined;
location /
{
#默认首页
index index.html index.htm;
#HTML网页存放的目录
root /data0/htdocs/server2;
}
}
#第三个虚拟机
server
{
#监听的ip和端口
listen 192.168.182.130:80;
#主机名称
server_name 192.168.182.130;
#访问日志文件的存放路径
access_log logs/server3.access.log combined;
location /
{
#默认首页
index index.html index.htm;
#HTML网页存放的目录
root /data0/htdocs/server3;
}
}
}
*************************************************************************************************
基于域名的虚拟主机配置
http
{
#第一个虚拟主机
server
{
#监听的端口
listen 80;
#主机名称
server_name aaa.domain.com;
#访问日志文件存放路径
access_log logs/aaa.domain.com.access.log combined;
location /
{
index index.html index.htm;
root /data0/htdocs/aaa.domain.com;
}
}
#第二个虚拟机
server
{
listen 80;
server_name bbb.otherdomain.com;
access_log logs/bbb.otherdomain.com.access.log combined;
location /
{
index index.html index.htm;
root /data0/htdocs/bbb.otherdomain.com;
}
}
#第三个虚拟主机
server
{
listen 80;
server_name www.domain.com domain.com *.domain.com;
access_log logs/bbb.domain.com.access.log combined;
location /
{
index index.html index.htm;
root /data0/htdocs/domain.com;
}
}
}
****************************************************************************************************
Nginx的日志文件配置与切割
access_log用于指定日志文件的存放路径 格式 和缓存大小
log_format用来设置日志的格式
log_format name format [format ...]
name表示定义的格式名称,format表示定义的格式,log_format有一个默认的,无须设置的combined日志格式设置,相当于Apache的combined日志格式
log_format combined '$remote_addr - $remote_user[$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
log_format mylogformat '$http_x_forwarded_for - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent"';
access_log path [format [buffer=size | off]]
1>access_log off; 表示不想记录日志
2>access_log /data1/logs/filename.log;
或者 access_log /data1/logs/filename.log combined
3>access_log /data1/log/access.log mylogformat buffer=32k;
4>Nginx0.7.4之后的版本中access_log指令中的日志文件路径可以包含变量
access_log /data1/logs/$server_name.log combined
***如果文件路径含有变量有一下限制
1.Nginx进程设置的用户和组必须有对该路径创建文件的权限
2.缓冲不会被使用
3.对每一条日志记录,日志文件都将先打开文件,再写入日志记录,然后关闭,为提高性能,须要使用open_log_file_cache指令设置经常被使用的日志文件描述符缓存,语法如下:
open_log_file_cache max=N [inactive=time] [min_uses=N] [valid=time] | off
默认为off
max : 设置缓存中最大文件描述符数量
inactive: 设置一个时间,如果设置的时间内没有使用此文件描述符,默认10s
min_uses:在参数inactive指定的时间范围内,如果日志文件超过使用的次数,将将该日志文件的描述符计入缓存,默认次数为1.
valid:设置多长时间检查一次,看一看变量指定的日志文件路径是否仍然存在.默认为60秒
open_log_file_cache max=1000 inactive=20s min_uses=2 valid=1m;
*********************************************************************************************
Nginx日志文件的切割
Nginx不支持像Apache一样使用cronolog来轮转日志,但可以使用kill -USR1实现日志文件的切割
mv /data1/logs/access.log /data1/logs/20090318.log
kill -USR1 Nginx主进程
可以借助crontab每天定时切割日志
vi /usr/local/nginx/sbin/cut_nginx_log.sh
cut_nginx_log.sh内容如下:
============================================================
#!/bin/bash
#这个脚本在每天的00:00运行
#Nginx日志文件的存放路径
logs_path="/data1/logs/"
mkdir -p ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/
mv ${logs_path}www.juzihc.com.log ${logs_path}$(date -d "yesterday" +"%Y")/$(date -d "yesterday" +"%m")/juzihc_$(date -d "yesterday" +"%Y%m%d").log
kill -USR1 $(cat /usr/local/nginx/logs/nginx.pid)
============================
chmod +x /usr/loca/nginx/sbin/cut_nginx_log.sh
crontab -e
=============================================================
00 00 * * * /bin/bash /usr/local/nginx/sbin/cut_nginx_log.sh
=============================
***********************************************************************************************************
Nginx的压缩输出配置
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
Nginx的自动列目录配置
前提条件在当前目录下不存在用index指令设置的默认首页设置
location /
{
autoindex on;
}
atuoindex_exact_size [on | off] 设置索引文件大小的单位(B KB MB或GB)
autoindex_localtime [on | off] 开启以本地时间来显示文件时间的功能默认为关
Nginx的浏览器本地缓存设置
通过expires指令输出Header头来实现,expires指令的语法如下:
expires [time | epoch | max | off]
epoch 指定Expires的值为1 January,1970,00:00:01 GMT
max 指定Expires的值为31 December 2037 23:59:59 GMT, Cache-Control的值为10年, -1指定Expires的值为服务器当前-1s,即永远过期
Cache-Control
time为负数:Cache-Control:no-cache
time为正数或零:Cache-Control:max-age=指定的时间的秒数
off表示不修改Expires和Cache-Control的值
默认值: expires off
作用域: http , server , location
对常见格式的图片,flash文件在浏览器本地缓存30天,对js,css文件在浏览器本地缓存一小时
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}