Nginx配置文件说明


#user  nobody;
#顶层配置信息管理服务器级别行为

#阻塞和非阻塞网络模型
#同步阻塞模型,一请求一进(线)程,当进(线)程增加到一定程度后
#更多cpu时间浪费到切换一,性能急剧下降,所以负载率不高
#Nginx基于事件的非阻塞多路复用(epoll或kquene)模型
#一个进程在短时间内可以响应大量的请求
#建议值 <= cpu核心数量,一般高于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;

#event指令与事件模型有关,配置处理连接有关信息
events {
    worker_connections  1024;
}



#http指令处理http请求    接受请求交给server处理
http {
#mime type映射
    include       mime.types;  #映入mime.type映射文件
    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;      #启用内核复制模式,应该保持开启达到IO效率
    #tcp_nopush     on;


    #http1.1支持持久连接alive
    #降低每个连接的alive时间可在一定程度上提高可响应连接数量,所以一般可适当降低此值
    #keepalive_timeout  0;   
    keepalive_timeout  65;

    #启动内容压缩,有效降低网络流量
    #gzip  on;


#配置负载均衡时 的后端服务器组
upstream tomcats{
#均衡策略
#none 轮询(由weight决定)
#ip_hash
#fair
#url_hash

server 192.168.162:8080;
server 192.168.163:8080;

server 192.168.164 weight=5;  #weight:权重,值越高负载越大

server 192.168.164 backup;   #备份机,只有非备份机都挂掉了才启用

server 192.168.164 down;    #停机标志,不会被访问

}
server{
listen     80;
server_name localhost;
location /{
index  index.html index.htm;
proxy_pass http://tomcats;    #将请求发到后端服务器组tomcats

}
}


# server 表示一个虚拟主机,一台服务器可配置多个虚拟主机
    server {
      #监听端口
        listen       8080;
        
        #识别的域名
        server_name  127.0.0.1;

#一个关键设置,与url参数乱码问题有关
        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        
        
        

#location表达式
#syntax: location [=|~*|^~|@] /uri/{...}
#分为两种匹配模式,普通字符串匹配,正则匹配
#无开头引导字符或以=开头表示普通字符串匹配
#以~或~*开头表示正则匹配,~*表示不区分大小写
#多个location时匹配规则
#总体是先普通后正则原则,只识别uri部分,例如请求为/test/1/abc.do?arg=xxx 
#1. 先查找是否有=开头的精确匹配,即location = /test/1/abc.do{...}
#2. 再查找普通匹配,以 最大前缀 为规则,如有以下两个location
#   location /test/ {...}
#   location /test/1/ {...}
#   则匹配后一项
#3.匹配到一个普通格式化,搜索并未结束,而是暂存当前结果,并继续在搜索正则模式
#4.在所以正则模式location中找到<第一个>匹配项后,以此匹配项为最终结果
#  所以正则匹配匹配项匹配规则受定义前后顺序影响,但普通匹配不会
#5.如果未找到正则匹配项,则以3中缓存的结果为最终结果
#6.如果一个匹配都没有,返回404

#location =/{...}与location /{...}的差别
#前一个是精确匹配,只响应/请求,所有/xxx类请求不会以前缀匹配形式匹配到它
#而后一个正相反,所有请求必然都是以/开头,所以没有其他匹配结果时一定会执行到它

#location ^~ / {...} ^~意思是非正则,表示匹配到此模式后不再继续正则搜索
#所有如果这样配置,相当于关闭了正则匹配功能

        location / {
            root   html;   #所要找文件的根, window中绝对路径  d:/admin
            index  index.html index.htm;
            #deny all;     #拒绝请求,返回403
            #allow all;    #允许请求
        }
        


        #测试        
        location /a/ {
            proxy_pass   http://www.baidu.com/;
        }

  #定义各类错误页
        #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;
    #    }
    #}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值