## 全局块,配置影响nginx全局的指令 ##
#user nobody; #配置用户或者用户组,默认nobody nobody
worker_processes 1; #允许生成的进程数,默认为1
#error_log logs/error.log; #制定日志路径,级别。这个设置可以放入全局块,http块,server块,级别以此为:debug|info|notice|warn|error|crit|alert|emerg
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid /usr/local/var/run/nginx.pid; #指定nginx进程运行文件存放地址
## 配置nginx服务器或与用户的网络连接 ##
events {
#accept_mutex on; #设置网路连接序列化,防止惊群现象发生,默认为on
#multi_accept on; #设置一个进程是否同时接受多个网络连接,默认为off
#use epoll; #事件驱动模型,配置指定了线程轮询的方法,select|poll|kqueue|epoll|resig|/dev/poll|eventport
worker_connections 1024; #最大连接数,默认512
}
## 可以嵌套多个server,配置代理,缓存,日志定义等绝大多数功能和第三方模块的配置 ##
http {
include mime.types; #文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型,默认为text/plain
#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 logs/access.log main; #access.log使用 main格式
sendfile on; #允许sendfile方式传输文件,默认为off,可以在http块,server块,location块。将文件的回写过程交给数据缓冲去去完成,而不是放在应用中完成,这样的话在性能提升有有好处
tcp_nopush on; #让nginx在一个数据包中发送所有的头文件,而不是一个一个单独发
tcp_nodelay on; #让nginx不要缓存数据,而是一段一段发送,如果数据的传输有实时性的要求的话可以配置它,发送完一小段数据就立刻能得到返回值,但是不要滥用哦
#sendfile_max_chunk 100k; #每个进程每次调用传输数量不能大于设定的值,默认为0,即不设上限。
#keepalive_timeout 0;
keepalive_timeout 10; #连接超时时间,默认为75s,可以在http,server,location块。
server_tokens off; #虽然不会让nginx执行速度更快,但是可以在错误页面关闭nginx版本提示,对于网站安全性的提升有好处哦
##
# SSL证书配置
##
#ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
#ssl_prefer_server_ciphers on;
##
# 日志配置
##
access_log /var/log/nginx/access.log; #设置存储访问记录的日志
error_log /var/log/nginx/error.log; #设置存储记录错误发生的日志
##
# Gzip 压缩配置g
# zip 是告诉nginx采用gzip压缩的形式发送数据。这将会减少我们发送的数据量。
# gzip_disable 为指定的客户端禁用gzip功能。我们设置成IE6或者更低版本以使我们的方案能够广泛兼容。
# gzip_static 告诉nginx在压缩资源之前,先查找是否有预先gzip处理过的资源。这要求你预先压缩你的文件(在这个例子中被注释掉了),从而允许你使用最高压缩比,这样nginx就不用再压缩这些文件了(想要更详尽的gzip_static的信息,请点击这里)。
# gzip_proxied 允许或者禁止压缩基于请求和响应的响应流。我们设置为any,意味着将会压缩所有的请求。
# gzip_min_length 设置对数据启用压缩的最少字节数。如果一个请求小于1000字节,我们最好不要压缩它,因为压缩这些小的数据会降低处理此请求的所有进程的速度。
# gzip_comp_level 设置数据的压缩等级。这个等级可以是1-9之间的任意数值,9是最慢但是压缩比最大的。我们设置为4,这是一个比较折中的设置。
# gzip_type 设置需要压缩的数据格式。上面例子中已经有一些了,你也可以再添加更多的格式。
##
#gzip on; #是告诉nginx采用gzip压缩的形式发送数据。这将会减少我们发送的数据量
#gzip_disable "msie6"; #为指定的客户端禁用gzip功能。我们设置成IE6或者更低版本以使我们的方案能够广泛兼容
# 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;
## upstream模块主要负责负载均衡的配置,通过默认的轮询调度方式来分发请求到后端服务器 ##
#upstream name {
# ip_hash;
# server 192.168.1.100:8000;
# server 192.168.1.100:8001 down;
# server 192.168.1.100:8002 max_fails=3;
# server 192.168.1.100:8003 fail_timeout=20s;
# server 192.168.1.100:8004 max_fails=3 fail_timeout=20s;
# keepalive 64;
#}
###详解地址:https://www.cnblogs.com/biglittleant/p/8979915.html
##可以限流的地方:Context: http, server, location
# $binary_remote_addr 表示通过remote_addr这个标识来做限制,“binary_”的目的是缩写内存占用量,是限制同一客户端ip地址
# zone=one:10m表示生成一个大小为10M,名字为one的内存区域,用来存储访问的频次信息
# rate=1r/s表示允许相同标识的客户端的访问频次,这里限制的是每秒1次,还可以有比如30r/m的
limit_req_zone $binary_remote_addr zone=one:10m rate=1r/s;
# zone=one 设置使用哪个配置区域来做限制,与上面limit_req_zone 里的name对应
# burst=5,重点说明一下这个配置,burst爆发的意思,这个配置的意思是设置一个大小为5的缓冲区当有大量请求(爆发)过来时,超过了访问频次限制的请求可以先放到这个缓冲区内
# nodelay,如果设置,超过访问频次而且缓冲区也满了的时候就会直接返回503,如果没有设置,则所有请求会等待排队
limit_req zone=one burst=5 nodelay;
# 这个模块用来限制单个IP的请求数。并非所有的连接都被计数。只有在服务器处理了请求并且已经读取了整个请求头时,连接才被计数
# zone=one:10m表示生成一个大小为10M,名字为one的内存区域,用来存储访问的连接数,大约1.6w个
limit_conn_zone $binary_remote_addr zone=addr:10m
## 配置虚拟主机的相关参数,一个http中可以有多个server ##
server {
listen 80;
server_name localhost; #
#charset koi8-r;
location / { #表示匹配访问根目录
root html; #用于指定访问根目录时,访问虚拟主机的web目录
index index.html index.htm; #在不指定访问具体资源时,默认展示的资源文件列表
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html; #错误页
location = /50x.html {
root html;
}
location /offlinead {
proxy_pass http://127.0.0.1:8080/adserver/offlinead;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /adserver/offlinead {
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
##
# requesturl:http://localhost/offline/xxx -> http://127.0.0.1:8081/admonitor/offline
##
location /offline {
proxy_pass http://127.0.0.1:8081/admonitor/offline;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
##
# requesturl:http://localhost/admonitor/offline/xxx -> http://127.0.0.1:8081/admonitor/offline
##
location /admonitor/offline {
proxy_pass http://127.0.0.1:8081;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /bugtracer {
proxy_pass http://127.0.0.1:8088;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /website {
proxy_pass http://127.0.0.1:8088/website;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /adcaffe {
}
# 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 ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000; #监听端口
# listen somename:8080;
# server_name somename alias another.alias; #监听地址
# location / { #请求的url过滤
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
#include servers/*;
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/sites-enabled/*;
}