现在的位置: 首页 > 综合 > 正文

nginx配置文件

2018年06月07日 ⁄ 综合 ⁄ 共 1407字 ⁄ 字号 评论关闭

默认的主要配置文件是nginx.conf,主要内容如下

#使用的用户和组
user nobody nogroup;

#指定工作衍生进程数,一般配置与CPU核数相等或总核数的两倍
worker_processes  8;

#相当于 error_log  /data2/log/nginx/error.log error; 将错误日志输出到指定文件
error_log  /data2/log/nginx/error.log;

#events模块用于配置网络机制
events {

    #配置一个worker_process能同时处理的连接数,如果nginx 中worker_connections 值设置是1024,worker_processes 值设置是4,
    #按反向代理模式下最大连接数的理论计算公式:最大连接数 = worker_processes * worker_connections/4
    worker_connections  40960;
    
    #use用于指定网络I/O模型,linux系统推荐采用epoll模型,FreeBSD系统推荐采用kqueue模型
    use epoll;
}

#设置网站服务模块
http {
    #文件包含,引入mime.types文件
    include     mime.types;

    #设置使用的字符集,如果一个网站有多种字符集,请不要随便设置,应该让程序员在HTML代码中通过Meta标签设置
    #charset gb2312

    #设置客户端能够上传的文件大小
    #client_max_body_size 8m;

    #开启gzip压缩
    #gzip on;
    
    #定义日志输出格式模板,第二个参数为该log_format的模板名,在下面引用格式使用
    #第三个参数为日志输出格式定义
    log_format  post  '$remote_addr [$time_local] $request_time $request $request_body';       
    log_format  main  '$remote_addr - $remote_user [$time_local] $request '
              '"$status" $body_bytes_sent "$http_referer" '
              '"$http_user_agent" "$http_x_forwarded_for" $request_time';   
               
    #指定日志记录路径,使用默认的日志格式模版combined		
    access_log  /data2/log/nginx/access.log;
		
    #使用sendfile内核调用处理文件传输
    sendfile  on;
    
    #设置server name对应的hash表大小为4096
    server_names_hash_max_size 4096;
    
    #设置进入hash表最长的server name为512
    server_names_hash_bucket_size 512;    
    
    #服务器关闭一个连接之前等待的时间10s
    keepalive_timeout  10;
    
    #选择立即发送数据或者等待产生更多的数据(tcp_cork)然后再一次发送两种策略,这里是立即发送
    tcp_nodelay  on;
    
    #隐藏nginx的版本号
    server_tokens off;
   
    ## deny no hostname access
    #禁止IP访问服务器并返回500错误码
    server {
        listen 80 default;
        return 500;
    }

    #该命令的作用就是引入sites目录下以“.com”结尾的文件
    include sites/*.com;   
    
}

【上篇】
【下篇】

抱歉!评论已关闭.