Nginx1.8.1的配置文件详解

【Nginx-1.8.1.tar.gz的配置文件】

#user  nobody;  //表示运行的用户和组,比如user nginx nginx;表示设置以nginx用户和nginx组来运行
worker_processes  1;  
        //定义了nginx对外提供web服务时的worder进程数。最优值取决于许多因素,
        包括(但不限于)CPU核的数量、存储数据的硬盘数量及负载模式。
        如果不能确定可以根据cpu的核心数来更改,或者可以设置为“auto”来自动检测。

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
                                //nginx运行错误的日志存放位置。当然还可以指定错误级别.
#pid        logs/nginx.pid;   
                //指定主进程id文件的存放位置,虽然worker_processes != 1的情况下,会有很多进程,但管理进程只有一个。

events {
    worker_connections  1024;   //每一个进程可同时建立的连接数量
}

-------------------------------------------------//上面的都是全局配置,下面的是http协议主配置--------
http {

    --------------------------------->以下是Nginx后端服务配置项
    upstream backendserver1 {
        #nginx rr //向后端服务器分配请求任务的方式,默认为轮询
        #ip_hash   //如果指定了ip_hash,就是hash算法  
        #ip:port    //如果有多个服务节点,这里就配置多个
            server 192.168.60.99:8080; 
            server 192.168.60.100:8080;    
        #server 192.168.60.108:8080 backup;
            //backup表示,这个是一个备份节点,只有当所有节点失效后,nginx才会往这个节点分配请求任务        
        #server 192.168.60.107:8080 weight=100;  
            //weight,固定权重
    }
    --------------------------------->以上是Nginx后端服务配置项

    include       mime.types;    
            //安装nginx后,在conf目录下除了nginx.conf主配置文件以外,有很多模板配置文件,
            //这里就是导入这些模板文件

    default_type  application/octet-stream;  
            //HTTP核心模块指令,这里设定默认类型为二进制流,也就是当文件类型未定义时使用这种方式

    //下面是日志格式
    #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;    //当sendfile启用的时候,它才会启用

    #keepalive_timeout  0;  
    keepalive_timeout  65; 
                //指定一个连接的等待时间(单位秒),如果超过等待时间,连接就会断掉。
                //注意一定要设置,否则高并发情况下会产生性能问题。
    #gzip  on;  //开启数据压缩

---------------------------------------------//下面是服务实例的配置--------------------------------------
    server {
        listen       80;    //这个服务器实例监听的端口
        server_name  localhost;   //服务器实例名称

        #charset koi8-r;    //文字格式

        #access_log  logs/host.access.log  main;   //实例日志存放位置

        location / {          //location将按照规则分流满足条件的URL。"location /"您可以理解为“默认分流位置”
            root   html;      //定义服务器的默认网站根目录的位置,比如/usr/local/nginx-1.11.2/html
            index  index.html index.htm;   //定义首页文件,位于/usr/local/nginx-1.11.2/html目录下面
        }

        #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;         //重定向服务器错误到静态页面/50x.html(/usr/local/nginx-1.11.2/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、付费专栏及课程。

余额充值