#user nobody;
#开启进程数 <=cpu数
worker_processes 1;
#错误日志存放位置
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#进程号保存文件
#pid logs/nginx.pid;
#每个进程最大连接数(最大连接=连接数x进程数)默认1024
events {
worker_connections 1024;
}
http {
#文件扩展名与文件类型映射表
include mime.types;
#默认文件类型
default_type application/octet-stream;
#配置负载均衡 myapp自定义
upstream myapp {
#weight越大被分配到几率越高 后2个参数表示30s内2次访问失败 则这30s内不再访问这个服务器
server 192.168.1.1:8080 weight=2 max_fails=3 fail_timeout=30s;
server 192.168.1.2:8080 weight=1 max_fails=3 fail_timeout=30s;
}
#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;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 8077;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
# /是拦截匹配所有请求 =精确匹配 ^~匹配url路径 ~精确大小写匹配 ~*不区分大小写匹配 root后的html表示进入nginx安装路径下的html目录中 没设置访问路径则访问 index.html
location / {
#设置黑名单
#if($remote_addr = 192.1.1.1){
# return 401;}
root html;
index index.html index.htm;
}
#拦截后缀jsp的请求
#proxy_set_header定义了名为x-real-ip的请求头 值为请求人的ip地址
location ~* .jsp$ {
proxy_pass http://192.168.1.2:8080;
#proxy_pass http://myapp;这个用了负载均衡
proxy_set_header x-real-ip $remote_addr;
}
#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_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
}