nginx.conf文件内容
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
access_log on;
sendfile on;
#tcp_nopush on;
autoindex off;#文件目录
keepalive_timeout 65;
server_tokens off;#关闭nginx请求头(user-agent)信息
gzip on;
include /etc/nginx/conf.d/gzip.conf;
#定义一个名为allips的limit_req_zone用来存储session,大小是10M内存,
#以$binary_remote_addr 为key,限制平均每秒的请求为20个,
#1M能存储16000个状态,rete的值必须为整数,
#如果限制两秒钟一个请求,可以设置成30r/m
limit_req_zone $binary_remote_addr zone=allips:10m rate=10r/s;
#限制单个ip并发数
limit_conn_zone $binary_remote_addr zone=flv_down:10m;
include /etc/nginx/conf.d/default.conf;
}
gzip.conf文件内容
#p on; #开启gzip压缩输出
gzip_min_length 1k; #最小压缩文件大小
gzip_buffers 4 16k; #压缩缓冲区
gzip_http_version 1.0; #压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
gzip_comp_level 2; #压缩等级
gzip_types text/plain application/x-javascript text/css application/xml;
#压缩类型,默认就已经包含text/html,所以下面就不用再写了,写上去也不会有问题,但是会有一个warn。
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m; #开启限制IP连接数的时候需要使用
default.conf文件内容
upstream xxx{
server 127.0.0.1:9897;
}
#限制ip直接访问网站
server{
listen 80 default;
server_name _;
return 444;
}
server {
listen 80;
server_name xxx;
#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;
location /xxx {
#限制每ip每秒不超过20个请求,漏桶数burst为5
#brust的意思就是,如果第1秒、2,3,4秒请求为19个,
#第5秒的请求为25个是被允许的。
#但是如果你第1秒就25个请求,第2秒超过20的请求返回503错误。
#nodelay,如果不设置该选项,严格使用平均速率限制请求数,
#第1秒25个请求时,5个请求放到第2秒执行,
#设置nodelay,25个请求将在第1秒执行。
limit_req zone=allips burst=5 nodelay;
#限制单个ip并发数
limit_conn flv_down 5;
proxy_pass http://xxx/xxx;
include /etc/nginx/conf.d/proxy.conf;
}
location /xxx {
proxy_pass http://xxx/xxx;
include /etc/nginx/conf.d/proxy.conf;
}
location /xxx {
proxy_pass http://xxx/xxx;
include /etc/nginx/conf.d/proxy.conf;
}
location /xxx {
proxy_pass http://xxxx/xxx;
include /etc/nginx/conf.d/proxy.conf;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 505 506 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#拒绝访问目录
location ~ /WEB-INF {
deny all;
return 505;
}
#禁止访问可执行文件
location ~ /upload/(app|appHead)/.*.(php|pl|py|jsp|sh|cgi|php5|js)$ {
deny all;
return 506;
}
#非get post head 请求不响应
if ($request_method !~ ^(GET|HEAD|POST)$ ) {
return 444;
}
#include /etc/nginx/conf.d/dynsatic.conf;
}
proxy.conf文件内容
proxy_redirect off;
# nginx转发的host
proxy_set_header Host $host;
# nginx转发的ip
proxy_set_header X-Real-IP $remote_addr;
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #获取代理者的真实ip
client_max_body_size 100m;
client_body_buffer_size 2048k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_buffer_size 32k;
proxy_buffers 4 64k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
#proxy_set_header(设定header)
#proxy_hide_header(隐藏header)
#proxy_pass_header(通过header)
#proxy_connect_timeout(代理连接超时)
#proxy_send_timeout(代理发送超时)
#proxy_read_timeout(代理接收超时)
#proxy_temp_file_write_size(设定缓存文件夹大小)
#proxy_buffer_size(代理缓冲大小)
#proxy_buffers (代理缓冲)
#proxy_busy_buffers_size(高负荷下缓冲大小)
#proxy_ignore_client_abort(不允许代理端主动关闭连接
dynsatic.conf文件内容
#p的页面均交由tomcat或resin处理
location ~ .(jsp|jspx|action)?$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:9897;
}
#所有静态文件由nginx直接读取不经过tomcat或resin
location ~ .*.(htm|html|gif|jpg|jpeg|png|bmp|swf|ioc|rar|zip|txt|flv|mid|doc|ppt|pdf|xls|mp3|wma)$ {
expires 15d;
}
location ~ .*.(js|css)?$ {
expires 1h;
}