Centos 7 nginx-1.12.0 配置学习(一)

[root@bogon nginx]# vim nginx.conf


#user  nobody;                #运行用户
worker_processes  1;        #启动进程,通常设置成和cpu核心数相等

#全局错误日志及PID文件
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    #epoll 是多路复用IO中的一种方式
    #仅用于linux2.6以上的内核,可以大大提高nginx的性能
    use epoll
    #单个后台worker process进程的最大并发链接数
    worker_connections  1024;
    
    #并发总数是worker_processes与worker_connections 的乘积
    #在设置了反向代理的情况下,max_clients = worker_processes * worker_connections / 4
    #为什么除4,是一个经验值
    #根据以上条件,正常情况下的nginx server 可以应付的最大连接数为:4 * 8000 = 32000
    #worker_connections的值设置与物理内存大小有关
    #因为并发受IO约束,max_clients的值须小于系统可以打开的最大连接数
    #面系统可以打开的最大的文件数和内存大小成正比,一般1G内存的机器可以打开的文件数大约是10W左右
    #看看360M的内存可以打开多少文件句柄:
    #    cat /proc/sys/fs/file-max
    #    输出34336    32000 < 34336 ,既并发连接总数小于系统可以打开的文件句柄,系统可以承受
    #其实质也就是根据主机的物理CPU和内存进行配置
    #理论的并发总数可能会和实际有所偏差,因为主机还有其它的工作进程消耗
    #解除最大连接数设定:
    终极解除 linux 系统的最大进程数和最大文件打开数限制:

    #vim /etc/security/limits.conf

    # 添加如下的行

    * soft nproc 11000

    * hard nproc 11000

    * soft nofile 655350

    * hard nofile 655350
}


http {
    #设定mime类型,类型由mime.type文件定义
    include       mime.types;
    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高负载可设off
    sendfile        on;
    #tcp_nopush     on;
    #连接超时时间 
    #keepalive_timeout  0;
    keepalive_timeout  65;
    
    #开启gzip压缩
    #gzip  on;
    
    #设定请求缓冲
    client_header_buffer_size    128k;
    large_client_header_buffers    4 128k;
    
    #设定虚拟主机配置
    server {
        
        #侦听8080端口
        listen       8080;
        #定义使用 www.nginx.cn
        server_name  www.nginx.cn;

        #charset koi8-r;
                
        #设定本虚拟主机的访问日志
        access_log  logs/host.access.log  main;
        
        #默认请求
        location / {
            #设定服务器的默认网站根目录位置
            root   html;
            #设定首页索引文件名称
            index  index.html index.htm index.php;
        }
        
        #定义错误提示页面
        #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;
    #    }
    #}

}

今天太晚了,环境还没有测试,有待验证!

原文地址:https://www.cnblogs.com/EWWE/p/7113430.html