Nginx配置粗略整理

Nginx配置详解

参考nginx学习网站:http://tengine.taobao.org/book/chapter_02.html

user  admin;#这个是指定访问的用户

worker_processes  2;#进程数,可以设置为cpu核数

worker_cpu_affinity 00000001 00000010;#不同的进程使用不同的cpu

worker_rlimit_nofile 8192; #最大连接数



error_log   " /log/webserver/error_log"   notice;#错误日志的位置

pid         " /log/nginx.pid";#进程pid存放位置



events {

    use epoll;#linux 多路复用I/O接口,监控有哪些流是可处理的,时间复杂度为O(1)

    worker_connections  8192; #每一个进程的最大连接数

}



http {#http服务的相关配置

    include       mime.types; #引用另一个配置文件

    #include       upstream.conf;#负载均衡配置

    default_type  application/octet-stream;#默认文件类型



    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" "$http_cookie" "$http_user_agent" '

                      '$request_time $logid $remote_addr $server_addr $upstream_addr $host '

                      '"$http_x_forwarded_for" $product $subsys $tracecode $msec';#日志的模板



    access_log  " /log/webserver/access_log"  main;#连接日志



    client_body_temp_path /webserver/cache/client_body;#客户端请求正文的缓冲目录

    fastcgi_temp_path /webserver/cache/fastcgi;#存储超过缓冲区大小的fastcgi响应数据

    proxy_temp_path /webserver/cache/proxy;#储存代理服务器的缓存目录

    uwsgi_temp_path /webserver/cache/uwsgi;# uwsgi网关的缓存目录

    scgi_temp_path /webserver/cache/scgi;# scgi网关缓存目录



    #设定请求缓存

    server_names_hash_bucket_size 128;

    client_header_buffer_size 16k;

    large_client_header_buffers 4 128k;

    client_max_body_size 50m;

    client_body_buffer_size 1024k;



    sendfile        on;#高效传输模式

    tcp_nopush      on; #激活tcp_nopush参数可以允许把httpresponse header和文件的开始放在一个文件里发布,积极的作用是减少网络报文段的数量

    tcp_nodelay     on;#激活tcp_nodelay,内核会等待将更多的字节组成一个数据包,从而提高I/O性能



    fastcgi_connect_timeout 5;#nginx和fastcgi的连接超时时间,单位秒

    fastcgi_send_timeout 10;#nginx向fastcgi传送请求超时时间

    fastcgi_read_timeout 10;#nginx接受fastcgi响应请求超时时间

    fastcgi_buffer_size 128k;#nginx读取fastcgi响应第一部分缓冲区大小

fastcgi_buffers 4 256k;#整个响应需要缓冲区的个数和每个的大小。

fastcgi_busy_buffers_size 512k;#设置为fastcgi_buffers的两倍,整个数据请求缓存的大小

    fastcgi_temp_file_write_size 512k;#写入fastcgi_temp_file用多大的数据块

    fastcgi_intercept_errors on;#是否传递错误信息给客户端



    keepalive_timeout  0;#长连接等待下一次请求的最大时长,如果是0则不支持长连接

    #keepalive_timeout  65;



    gzip on; #开启gzip压缩功能

    gzip_min_length 1k;#设置允许压缩的最小字节数,小于1K可能会越压越大

    gzip_buffers 4 16k;#压缩缓冲区的大小

    gzip_http_version 1.0;#压缩的http版本

    gzip_comp_level 2;#压缩比率 1-9,压缩比越小,压缩越快

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

gzip_vary on;#前端缓存服务器缓存压缩过得页面



#安全设置

    policy_frame off;

    policy_path " /webserver/conf/";

    policy_dtdname policy.dtd;

    policy_docname policy.xml;

    policy_logpath " /log/webserver";

    policy_logfile policy.;

    policy_logsize 1600;

    policy_loglevel 4;



    uninitialized_variable_warn off;

    proxy_connect_timeout 15s;#连接超时时间

    proxy_read_timeout 10s;# 连接成功后_等候后端服务器响应时间

    proxy_send_timeout 10s;# 后端服务器数据回传时间

    proxy_buffer_size 64k; #nginx读取后端响应第一部分缓冲区大小

    proxy_buffers 4 64k;# 代理的后端服务器取得的响应内容,会放置到这里

    proxy_busy_buffers_size 128k; #设置为proxy_buffers的两倍,整个数据请求缓存的大小

proxy_temp_file_write_size 128k;#写入缓存文件的文件块大小



#重新设置发往后端的请求头

    proxy_set_header LOGID $logid;

    proxy_set_header Host $http_host;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_set_header REMOTE-HOST $remote_addr;

    proxy_set_header X-Forwarded-For $remote_addr;

    proxy_set_header CLIENTIP $remote_addr;

    proxy_http_version 1.1;



    port_in_redirect off;#redirect不要带端口

    set_real_ip_from 192.168.0.0/24;#真实ip

    real_ip_header CLIENTIP;#真实ip的header头

    underscores_in_headers on;#如果header name中包含下划线,则忽略

    server {#服务器配置

        listen          80;#端口

        server_name     www.app.com;#主机名

#########域名适配模块配置###############

        dna on;

        dna_adapt_path "www/conf/adaption";

        dna_url_adaption "device";

        dna_cookie_adaption "device";

        dna_log_path "/webserver/log/";

        #########OMP支持#######################

        #设置产品线

        set $product app;

        #设置子系统

        set $subsys all;

        if ($http_x_bd_product) {

            #从接入层获取产品线

            set $product $http_x_bd_product;

        }

        if ($http_x_bd_subsys) {

            #从接入层获取子系统

            set $subsys $http_x_bd_subsys;

        }

# 重定向

rewrite  /abc/def/index /cdb/asd/index break;

#防止获取所有的文件

location ~* /(\.svn|CVS|Entries){

    deny all;

}

location ~* /((.*)\.(.*)\/(.*)\.php){

    deny all;

}

location ~* /\.(sql|bak|inc|old)$ {

      deny all;

}

        location / {#http服务中,某些特定的URL对应的一系列配置项。

            index index.html;#首页顺序
            fastcgi_pass    'unix:/home/webroot/var/php-cgi.sock';#配置fastcgi
            include         fastcgi.conf;#fastcgi的配置变量名

            root  /var/www/app/htdocs;#网站程序存放目录

error_page 400 403 404 500 501 502 503 504 505 http://www.sjdklafdsjl;.com/error.html?status=$status; #错误页

        }

        #location 标签,根目录下的abc目录禁止访问

        location ~ /abc/ {

            deny all;

        }

    }

}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值