nginx配置文件nginx.conf详解

来源:互联网 发布:java web权限管理框架 编辑:程序博客网 时间:2024/06/16 03:09
nginx.conf
#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    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;    #tcp_nopush     on;    #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 / {            root   html;            index  index.html index.htm;        }        #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;    #    }    #}}

worker_processes

启动进程的数目,通常和cpu数目一致

error_log

全局错误日志

events{

use epoll;

worker_connections  1024;

}

events中配置工作模式以及连接数上限。

epoll是多路复用io中的一种方式,可以提高nginx性能;

worker_connections 就是单个启动进程worker_process最大并发链接数

并发总数 = worker_processes * worker_connections

http {
    include       mime.types;

    default_type  application/octet-stream;

设置mime类型,由mime.type定义,默认类型application/octet-stream

mime.type设置http响应的Content_Type

    #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;

记录详细日志信息,logs/access.log是日志具体的存储位置

    sendfile        on;

设置nginx是否调用sendfile()方法输出文件(对于下载或者磁盘重负载的应用可以设置为off,来平衡磁盘和I/O处理速度)

    #tcp_nopush     on;

nginx在一个数据包中发送所有头文件,而不需要一个一个发送

   #tcp_nodelay     on;

设置nginx不要缓存数据

    #keepalive_timeout  0;
    keepalive_timeout  65;

设置连接超时时间

    #gzip  on;

开启压缩(gzip格式)

    server {
        listen       80;

监听端口,80是默认端口

        server_name  localhost;

定义使用localhost访问

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;

定义网站根目录位置

            index  index.html index.htm;

设置首页索引文件名称

        }

        #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;    配置proxy_pass代理转发
        #}

        # 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服务器监听端口与地址

        #    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;
    #    }
    #}

}

upstream  name{

server ip1:port weight = 1;

server ip2:port weight = 2;

server ip3:port weight = 3;

}

upstream 实现负载均衡,以weight(权重)方式分发,权重越大被分配到的几率越大

client_header_buffer_size    128k; 

large_client_header_buffers  4 128k;

设置请求缓存,client_header_buffer_size是请求头缓冲区,超过了就会使用large_client_header_buffers




原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 脸上长红色的小疙瘩怎么办 脸上都是小米粒痘痘怎么办 小孩身上起风团疙瘩怎么办 脸上长疙瘩很痒怎么办 一个多月宝宝脸上有湿疹怎么办 脸上发红发痒起疙瘩怎么办 脸过敏了怎么办最简单 胸下垂应该怎么办19岁 身上的肉特别松怎么办 才30岁脸部松弛怎么办 脸上的皮肤很松怎么办 面部皮肤干燥起皮刺痛怎么办 脸上的皮肤很粗糙怎么办 脸上又红又痒怎么办 鲜红斑痣增生了怎么办 激光祛斑后色素沉着怎么办 白球鞋洗后发黄怎么办 夏天出汗妆花了怎么办 买的小产权房怎么办 嘴唇起皮怎么办小妙招 照相嘴巴是歪的怎么办 鼻子笑起来很宽怎么办 财运不好怎么办最近你有偏财 从小缺爱的人怎么办 一到晚上就怕死怎么办 碰到不讲理的人怎么办 遇到不讲理的人怎么办 蚰蜓虫子咬了怎么办 腰肌损伤怎么办恢复快 腰闪了怎么办最有效 墨兰严重烂根怎么办 铁兰花变绿了怎么办 1岁半宝宝吵瞌睡怎么办 28天宝宝吵瞌睡怎么办 2个月宝宝闹瞌睡怎么办 被刺猬的刺扎了怎么办 买电脑被坑了怎么办 买电脑被坑了怎么办啊 在电脑城被坑了怎么办 小狗20天不睁眼怎么办 金星秀停播沈南怎么办