nginx-配置说明

2020-02-15  本文已影响0人  G__yuan

#user  nobody;     // 以什么的用户权限去运行当前的nginx,默认为nobody,用ps 查看nginx进程时,就可以看到主进程是root,工作进程 nobody   nobody 是个低权限用户

worker_processes  1;   //工作进程数,配置根据cpu的内核数来进行配置,通常设置成cpu的核数  查看cpu信息:cat /proc/cpuinfo

#error_log  logs/error.log;

#nginx的error_log类型如下(从左到右:debug最详细 crit 最少):

#【 debug | info | notice | warn | error | crit 】

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

#这个参数标示worker进程最多能打开的文件句柄数,基于linux系统ulimit设置

#查看系统文件句柄数最大值: ulimit -n    查看系统的

#linux一切皆文件,所有请求过来最终的访问文件,所以该参数设置等同于linux系统ulimitshe设置

#可以通过linux命令设置,最大的文件句柄数65535

worker_rlimit_nofile        65535

events {

    use   epoll  #网络模型高效(相当于建立索引查找结果)nginx配置应该启用该参数,但是仅用于linux2.6以上内核,可以打打提高nginx的性能。

    worker_connections  1024;  //限制指的是单个worker对并发的连接数。 #该参数表示设置一个worker进程最多开启多少线程数   #优化设置应该等同于worker_rlimit_nofile设置值,表明一个线程处理一个http请求,同时可以处理一个文件数,各个模块之间协调合作不等到

}

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;  //开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为on,如果用来进行下载等应用磁盘IO重负载应用,可设置横off,以平衡磁盘于网络IO处理速度,降低系统的负载,注意,如果图片显示不正常把这个改为off。

    #tcp_nopush    on;  # 防止网络阻塞

    #tcp_nodelay    on; # 防止网络阻塞

    #keepalive_timeout  0;

    keepalive_timeout  65; #连接超时时间,单位是秒

    gzip  on;  开启gzip压

    gzip_disable   "MSIE [1-6]\.";    # IE6及以下禁止压缩

    gzip_min_length  1k;     # 最小压缩文件大小

    gzip_buffers   4  16k;     #压缩缓冲区

    gzip_http_version 1.0;  #压缩版本(默认1.1,前段如果是squid2.5请使用1.0)

    gzip_comp_level  2; #压缩等级

    gzip_types  text/plain application/x-javascript text/css application/xml ; # 压缩类型

    gzip_vary on; # 给 CDN和代理服务器使用,针对相同URL,可以根据头信息返回压缩和非压缩副本

    #设定请求缓冲

    client_header_buffer_size  1k;    #上传文件大小限制

    large_client_header_buffers  4 4k;  #设定请求缓存

    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;

        #}

        location / {

            root /root;   #定义服务器的默认网站根目录位置

            index index.php index.html index.htm;  #定义首页索引文件的名称

            proxy_pass  http://mysvr ; #请求转向mysvr 定义的服务器列表

            #以下是一些反向代理的配置

            proxy_redirect off;

            #后端的web服务器可以通过X-Forwarded-For获取用户真实IP

            proxy_set_header Host $host;

            proxy_set_header X-Real_IP $remote_addr;

            pro_set_header X-Forwarded-For $proxy_add_x_forwarded_for; #用户真实ip

            client_max_body_size 10m;  #允许客户端请求的最大单文件字节数

            client_body_buffer_size 128k; #缓冲区代理缓冲用户端请求的最大字节数

            proxy_connect_timeout 90;  #nginx跟后端服务器连接超时时间(代理连接超时)

            proxy_send_timeout 90;  # 后端服务数据回传时间(代理发送超时)

            proxy_read_timeout 90; # 连接成功后,后端服务器响应时间(代理接收超时)

            proxy_buffer_size 4k;  # 设置代理服务器(nginx)保存用户头信息的缓冲区大小

            proxy_buffers 4 32k;   # proxy_buffers缓冲区,网页平均在32k以下的话,这样设置

            proxy_busy_buffers_size 64k;  # 高负荷缓冲大小(proxy_buffers * 2)

            proxy_temp_file_write_size 64k;  # 设定缓存文件夹大小,大于这个值,将从upstream 服务器传

        }

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

    #    }

    #}

}

上一篇 下一篇

猜你喜欢

热点阅读