upstream name{ #负载均衡配置,默认通过轮询调度
ip_hash; #指定请求调度算法,默认是weight权重轮询调度
server 192.168.1.100:8000;
server 192.168.1.100:8001 down; #表示该主机暂停服务
server 192.168.1.100:8002 max_fails=3; #表示失败最大次数为3次,超过失败最大次数暂停服务
server 192.168.1.100:8003 fail_timeout=20s; #表示如果请求受理失败,暂停指定的时间之后重新发起请求。
server 192.168.1.100:8004 max_fails=3 fail_timeout=20s;
}
#user nobody; #指定nginx worker进程运行用户以及用户组。
worker_processes 2; #启动进程数
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
error_log /var/log/nginx/error.log; #定义错误日志输出位置,后面的[notice info] 定义输出的级别,不填则输出全部
#pid logs/nginx.pid; #指定进程id的存储文件的位置
worker_rlimit_nofile 1024; #指定一个进程可以打开最多文件数量
events {
worker_connections 1024; #最大连接数
#multi_accept on; #配置nginx收到新的链接后尽可能多的接受更多的链接
#use epoll; #使用线程轮询的方式
}
http {
#sendfile on; #文件回写过程交给数据缓冲去完成,不是在应用中完成,可提升性能
tcp_nopush on;#让nginx在一个数据包中发送所有的头文件
#tcp_nodelay on;#让nginx不要缓存数据 一段段发送,针对传输有实时性的要求配置。
keepalive_timeout 65; #给客户端分配连接超时时间,超时后关闭连接
#client_header_timeout 10:#设置请求头的超时时间
#client_body_timeout 10:#设置请求体的超时时间
#send_timeout 10:#指定客户端响应超时时间,如果客户端两次操作间隔超过这个时间,服务器就会关闭这个链接
#limit_conn_zone $binary_remote_addr zone=addr:5m :#设置用于保存各种key的共享内存的参数,
#limit_conn addr 100:# 给定的key设置最大连接数
# server_tokens off; #在错误页面关闭nginx版本提示,对于网站安全性的提升有好处
#types_hash_max_size 2048; #混淆数据,影响三列冲突率,值越大消耗内存越多,散列key冲突率会降低,检索速度更快;值越小key,占用内存较少,冲突率越高,检索速度变慢
include 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 logs/access.log main;
access_log /var/log/nginx/access.log; #设置存储访问记录的日志
error_log /var/log/nginx/error.log; #设置存储记录错误发生的日志
sendfile on;
#tcp_nopush on;
#gzip on; #是告诉nginx采用gzip压缩的形式发送数据。这将会减少我们发送的数据量。
#gzip_disable "msie6"; 为指定的客户端禁用gzip功能。 设置成IE6或者更低版本为了兼容
#gzip_static 告诉nginx在压缩资源之前,先查找是否有预先gzip处理过的资源。
# gzip_proxied any; #允许或者禁止压缩基于请求和响应的响应流。设置为any,意味着将会压缩所有的请求。
# gzip_comp_level 6; #设置数据的压缩等级
# gzip_types text/plain text/css application/json application/javascript
text/xml application/xml application/xml+rss text/javascript; #设置需要压缩的数据格式。
include /etc/nginx/conf.d/*.conf; #包含其他的conf配置文件
# server {
# listen 80;
# server_name localhost; #指定ip地址或者域名,多个配置之间用空格分隔
# root /nginx/www; #表示整个server虚拟主机内的根目录
# #charset utf-8; #用于设置www/路径中配置的网页的默认编码格式
#
# #access_log logs/host.access.log ; #用于指定该虚拟主机服务器中的访问记录日志存放路径
# #error_log logs/host.error.log; #用于指定该虚拟主机服务器中访问错误日志的存放路径
# location / { #用于配置路由访问信息 /:表示匹配访问根目录
# root html; #用于指定访问根目录时,访问虚拟主机的web目录
# index index.html index.htm; #在不指定访问具体资源时,默认展示的资源文件列表
# }
# location /api { #**设置反向代理服务器访问模式**
#
# proxy_set_header X-real-ip $remote_addr; #自定义一个变量X-real-ip值为用户的ip地址
# proxy_set_header Host $http_host;#定义请求时的域名
# add_header Cache-Control no-cache; #设置不使用缓存
# proxy_pass http://"负载均衡名称";
# }
# location /uwapi { #**设置uwsgi模式下的服务器访问方式**
# include uwsgi_params;
# uwsgi_pass localhost:8888
# }
#
# #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;
# }
#
# # 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 / {
# 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_protocols:指令用于启动特定的加密协议,nginx在1.1.13和1.0.12版本后默认是ssl_protocols SSLv3 TLSv1 TLSv1.1 TLSv1.2,TLSv1.1与TLSv1.2要确保OpenSSL >= 1.0.1 ,SSLv3 现在还有很多地方在用但有不少被攻击的漏洞。
# ssl_prefer_server_ciphers on; #设置协商加密算法时,优先使用我们服务端的加密套件
# location / {
# root html;
# index index.html index.htm;
# }
#}
}