hc6538 发表于 2018-11-10 09:47:51

nginx-1.14.0 使用

  #usernobody;       #用户
  worker_processes1; #工作进程,根据硬件调整,大于等于CPU核数
  #error_loglogs/error.log;#错误日志配置
  #error_loglogs/error.lognotice;
  #error_loglogs/error.loginfo;
  #pid      logs/nginx.pid; #pid放置位置
  events {
  #use epoll;
  #使用epoll的I/O 模型
  # 补充说明:
  #与apache相类,nginx针对不同的操作系统,有不同的事件模型
  #A)标准事件模型
  #Select、poll属于标准事件模型,如果当前系统不存在更有效的方法,nginx会选择select或poll
  #B)高效事件模型
  #Kqueue:使用于FreeBSD 4.1+, OpenBSD 2.9+, NetBSD 2.0 和 MacOS X.使用双处理器的MacOS #X系统使用kqueue可能会造成内核崩溃。
  #Epoll:使用于Linux内核2.6版本及以后的系统。
  #/dev/poll:使用于Solaris 7 11/99+, HP/UX 11.22+ (eventport), IRIX 6.5.15+ 和 Tru64 UNIX 5.1A+。
  #Eventport:使用于Solaris 10. 为了防止出现内核崩溃的问题, 有必要安装安全补丁
  worker_connections1024;
  #工作进程的最大连接数量,根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行
  #每个进程允许的最多连接数, 理论上每台nginx服务器的最大连接数为worker_processes*worker_connections
  keepalive_timeout 60;
  }
  #设定http服务器,利用它的反向代理功能提供负载均衡支持
  http {
  include       mime.types;
  default_typeapplication/octet-stream;
  sendfile      on;
  #tcp_nopush   on;
  #keepalive_timeout0;
  keepalive_timeout65;
  #gzipon;
  #配置两台Tomcat真实服务器
  upstreamB2C_WEB {
  #ip_hash;   #目的保证客户端的ip地址不变,请求就只送到固定的一个Tomcat处理
  server 192.168.126.1:8080 weight=1 max_fails=3 fail_timeout=30s;
  server 192.168.126.15:8080 weight=1 max_fails=3 fail_timeout=30s;
  #weight=1表示
  #这表示,如果服务器192.168.126.1 | 15在30秒内出现了3次错误,
  #那么就认为这个服务器工作不正常,从而在接下来的30秒内nginx不再去访问这个服务器。
  }
  server {
  listen       80; #监听端口
  server_namelocalhost;
  charset UTF-8;
  index index.html index.htm index.jsp index.do;
  root E:\\JavaEE\\Apache-Tomcat-7.0.41\\wtpwebapps; #WEB服务的主目录
  location ~ ^/(WEB-INF)/ {
  deny all; #禁止访问WEB-INF目录
  }
  # 动态数据由代理服务器Tomcat处理
  location ~ .*\.(jsp|jspx|do)?$ {
  proxy_pass http://B2C;# 反向代理
  proxy_set_headerX-Real-IP $remote_addr;
  proxy_next_upstream http_502 http_504 error timeout invalid_header;
  }
  # 静态数据直接读取不经过Tomcat服务器
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  {
  expires      30d; #在客户端保存时间
  }
  location ~ .*\.(js|css)?$
  {
  expires      1h;
  }
  # 监控Nginx服务状态
  location /Nginxstatus {
  stub_status on;
  access_log   off;
  }
  #charset koi8-r;
  #access_loglogs/host.access.logmain;
  #error_page404            /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;
  }
  }
  }

页: [1]
查看完整版本: nginx-1.14.0 使用