[root@Python conf]# cat nginx.conf
user nobody; # 设置用户和用户组,默认nobody;
worker_processes 1; # 设置运行Nginx的CPU的个数,通常略少于服务器CPU个数;
error_log logs/error.log notice;
## 设置错误日志,[ debug|info|notice|warn|error|crit ] 定义级别,debug最详细,crit最简单;
## 关闭错误日志,error_log /dev/null crit;
pid logs/nginx.pid; # 把nginx进程号记录到文件,用于管理nginx进程;
events {
worker_connections 1024; # 单个CPU的最大连接数;
}
http {
include mime.types; # 纳入mime.types文件的配置;
# include表示加载别的配置文件;
# mime.types理解为一种web服务器的通用规范,不必深究;
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; ## 设置访问日志;
sendfile on; # 开启文件快速传输,sendfile是一个比read和write更高性能的接口;
# nginx作为http服务器开启此项提高性能;
tcp_nopush on; # 是否缓存数据后集中发送,适用于大文件传输;
tcp_nodelay on; # 是否立即发送数据包,使用于即时性传输;
keepalive_timeout 0;
keepalive_timeout 65; # 设置连接超时时间;
gzip on; # 开启gzip压缩功能;
upstream tomcat {
ip_hash;
server 172.19.0.117:8080 weight=90;
server 172.19.0.118:8080 weight=60;
server 172.19.0.119:8000 backup;
}
## upstrem模块中设置负载均衡规则,然后在server模块中进行调用完成负载均衡配置;
## weight设置权重,可不设置,以轮询方式;可设置backup备用服务器;
## ip_hash,每一个ip地址按哈希结果固定一个后端服务器,解决session的问题;
server {
listen 80;
server_name www.syztoo.com;
rewrite ^(.*)$ https://${server_name}$1 permanent;
## 将所有80端口的请求重定向到443端口;
}
server {
listen 443 ssl;
server_name www.syztoo.com;
ssl_certificate cert/www.syztoo.com.pem;
ssl_certificate_key cert/www.syztoo.com.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
## https 配置;
location = / {
proxy_pass http://tomcat;
## 调用定义的tomcat负载均衡规则;
}
}
}