nginx详细配置说明

#nginx的工作进程的用户以及用户组, windows不需要配置
#user  nobody;
#工作进程个数,通常配置为cpu总和数
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;
#单个woker进程最大打开文件数,进程最大可打开文件数受限于操作系统,可通过 ulimit -n 命令查询,以前是1024,现在是65535
#设置后你的操作系统和Nginx可以处理比“ulimit -a”更多的文件,所以把这个值设高,这样Nginx就不会有“too many open files”问题了
#建议与ulimit -n 的值保持一致
worker_rlimit_nofile 65535;

events {
	#网络连接事件IO模型
	use epoll;
	#单个woker进程并发处理的连接数,不能大于worker_rlimit_nofile。整个nginx进程总的并发连接数=worker_connections*worker_processes
	#将此配置调大可增加nginx的吞吐量,但是设置过高也会大量占用内存和CPU
    worker_connections  10240;
}


http {
	#MIME类型 conf/mime.types
    include       mime.types;
	#默认MIME类型
    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;
	
	
	
	#设置来自客户端的请求标头的标头缓冲区大小,默认1k,对于绝大多数请求,缓冲区大小完全为1K就足够了。
	client_header_buffer_size 128k;
	#设置用于读取大型客户端请求标头的缓冲区的最大数量和大小。 请求行不能超过一个缓冲区的大小,否则会向客户端返回414(请求URI太大)错误。
	#请求标头字段也不能超过一个缓冲区的大小,否则会将400(错误请求)错误返回给客户端。
	#先根据client_header_buffer_size配置的值分配一个buffer,如果分配的buffer无法容纳 request_line/request_header,
	#那么就会再次根据large_client_header_buffers配置的参数分配large_buffer,如果large_buffer还是无法容纳,
	#那么就会返回414(处理request_line)/400(处理request_header)错误。
	large_client_header_buffers 8 128k;
	


	#sendfile可以让Nginx在传输文件时直接在磁盘和tcp socket之间传输数据,
	#对于普通应用,必须设为on。如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络IO处理速度,降低系统uptime。
    sendfile        on;
    #tcp_nopush     on;

	#长连接超时时间
    #keepalive_timeout  0;
    keepalive_timeout  65;
	
	#允许客户端请求的最大单文件字节数。如果有上传较大文件,请设置它的限制值
	#client_max_body_size 10m
	#缓冲区代理缓冲用户端请求的最大字节数
	client_body_buffer_size 512k

	#FastCGI相关参数.解析php脚本语言配置
	#fastcgi_connect_timeout 300;
	#fastcgi_send_timeout 300;
	#fastcgi_read_timeout 300;
	#fastcgi_buffer_size 64k;
	#fastcgi_buffers 4 64k;
	#fastcgi_busy_buffers_size 128k;
	#fastcgi_temp_file_write_size 128k;
	

	#gzip模块设置
	gzip on; #开启gzip压缩输出
	gzip_min_length 1k; #最小压缩文件大小 建议设置成大于1k的字节数,小于1k可能会越压越大
	gzip_buffers 4 16k;
	#压缩版本(默认1.1,前端如果是squid2.5请使用1.0)
	#这里配置在某种情况下会出现问题,文章:https://www.cnblogs.com/zs-note/p/9556390.html
	#gzip_http_version 1.1; 
	gzip_comp_level 4; #压缩等级
	#图片/MP3这样的二进制文件不用压缩.压缩率太小且消耗CPU
	gzip_types text/plain application/x-javascript text/css application/xml;
	#配置禁用gzip条件,支持正则。此处表示ie6及以下不启用gzip(因为ie低版本不支持)
	gzip_disable "MSIE [1-6]\."; 
	#是否添加“Vary: Accept-Encoding”响应头
	#gzip_vary on;
	#gzip_static是nginx对于静态文件的处理模块,可以读取预先压缩的gz文件
	#gzip_static on|off:默认off	

	
    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

	######proxy模块配置 可放到http,server,location模块配置######	
	#nginx跟后端服务器连接超时时间(代理连接超时)
	proxy_connect_timeout 60
	#连接成功后,与后端服务器两个成功的响应操作之间超时时间(代理接收超时)
	proxy_read_timeout 60
	#设置代理服务器(nginx)从后端realserver读取并保存用户头信息的缓冲区大小,默认与proxy_buffers大小相同,其实可以将这个指令值设的小一点
	proxy_buffer_size 4k
	#该指令设置缓冲区的大小和数量,从被代理的后端服务器取得的响应内容,会放置到这里. 默认情况下,一个缓冲区的大小等于页面大小,可能是4K也可能是8K,这取决于平台,网页平均在32k以下的话,这样设置
	proxy_buffers 4 32k
	#高负荷下缓冲大小(proxy_buffers*2)
	proxy_busy_buffers_size 64k
	#当缓存被代理的服务器响应到临时文件时,这个选项限制每次写临时文件的大小。
	proxy_temp_file_write_size 64k;
	#当 proxy_buffers 放不下后端服务器的响应内容时,会将一部分保存到硬盘的临时文件中,这个值用来设置最大临时文件大小,默认1024M,
	proxy_max_temp_file_size 1G
	
	#后端服务器获取真实用户ip
	proxy_set_header Host $host;
	proxy_set_header X-Real-IP $remote_addr;
	proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

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

}

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值