鱼C论坛

 找回密码
 立即注册
查看: 2782|回复: 0

nginx.conf详解

[复制链接]
发表于 2011-10-11 16:43:45 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 黑夜 于 2011-10-11 16:44 编辑

#使用哪个用户启动nginx 前面是用户,后面是组
user  www www; #nginx工作的进程数量
worker_processes 2;

# [ debug | info | notice | warn | error | crit ]   错误日志的位置
error_log  /var/htdocs/logs/nginx_error.log  crit;

#进程号保存文件
pid /usr/local/nginx/nginx.pid;
#最大文件描述符 ?有待继续整理.
worker_rlimit_nofile 51200;
events
{
     # use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
     use epoll;  #使用epoll(linux2.6的高性能方式)
     worker_connections 51200; #每个进程最大连接数(最大连接=连接数x进程数)
}
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"';

    log_format download  '$remote_addr - $remote_user [$time_local] '
                             '"$request" $status $bytes_sent '
                             '"$http_referer" "$http_user_agent" '
                             '"$http_range" "$sent_http_content_range"';
     #默认编码
     charset  gb2312,utf-8;
   
     server_names_hash_bucket_size 128;
     #开启高效文件传输模式
     sendfile on;
     #以下两个选项用于防止网络阻塞 参考http://i.cn.yahoo.com/nesta2001zhang/blog/p_104/
     tcp_nopush     on;
     tcp_nodelay on;


     #长链接超时时间
     keepalive_timeout 300;

     #fastcgi连接超时时间,下面的看字面意思都能理解个大概了,就不解释了.
     fastcgi_connect_timeout 300;
     fastcgi_send_timeout 300;
     fastcgi_read_timeout 300;
     fastcgi_buffer_size 128k;
     fastcgi_buffers 4 256k;
     fastcgi_busy_buffers_size 256k;
     fastcgi_temp_file_write_size 256k;
     fastcgi_temp_path /dev/shm;
     #打开gzip压缩
     gzip on;
     #最小压缩文件大小
     gzip_min_length  1k;
     #压缩缓冲区
     gzip_buffers     4 8k;
     #压缩版本(默认1.1,前端为squid2.5使用1.0)
     gzip_http_version 1.1;
     #压缩类型,默认就已经包含text/html 所以下面就不用再写了,当然写上去的话,也不会有问题,但是会有一个warn
     gzip_types       text/plain application/x-javascript text/css text/html text/javascript application/xml;
     #错误页面
     error_page 404 http://www.g.cn;
     error_page 403 http://www.g.cn;
     #上传文件大小限制
     client_max_body_size 20m;
     #设定请求缓
     client_header_buffer_size 16k;
     large_client_header_buffers 4 64k;
     #设定负载均衡的服务器列表
     #如果在同一台机器上,单独起4组独立的php-cgi进程(每组8个子进程),性能应该不如1组php-cgi进程(32个子进程),因为1组进程,eaccelerator的PHP二进制文件缓存是共享的,1组进程命中率较高。
     #不过好处是,碰到某组的php假死的话,其他端口就可以接管了,我实测下来似乎发生502错误的概率降低了很多,或者说我这样配置以后还没有遇到
     upstream mysvr {
             #weigth参数表示权值,权值越高被分配到的几率越大
             #本机上的Squid开启3128端口
             server 192.168.8.1:3128 weight=5;
             server 192.168.8.2:80   weight=1;
             server 192.168.8.3:80   weight=6;
     }
     #下面开始虚拟主机的配置
     server
     {
             listen       80;
             server_name  www.52crack.com;
             index index.html Index.html index.htm index.php;
             root  /var/htdocs/52crack;
             if (-d $request_filename)
             {
                    rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
             }
             #设定本虚拟主机的访问日志
             access_log  logs/www.52crack.com.access.log  main;
             location ~ .*.php?$
             {
                  include fcgi.conf;
                  fastcgi_pass  127.0.0.1:9000;
                  fastcgi_index index.php;
             }
             #如果访问 /img/*, /js/*, /css/* 资源,则直接取本地文件,不通过squid
             #如果这些文件较多,不推荐这种方式,因为通过squid的缓存效果更好
             location ~ ^/(img|js|css)/  {
                     root    /var/htdocs/52crack;
                     expires 24h;
             }
             #对 "/" 启用负载均衡
             location / {
                     proxy_pass      http://127.0.0.1;
                     proxy_redirect          off;
                     proxy_set_header        Host $host;
                     proxy_set_header        X-Real-IP $remote_addr;
                     proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                     client_max_body_size    10m;
                     client_body_buffer_size 128k;
                     proxy_connect_timeout   90;
                     proxy_send_timeout      90;
                     proxy_read_timeout      90;
                     proxy_buffer_size       4k;
                     proxy_buffers           4 32k;
                     proxy_busy_buffers_size 64k;
                     proxy_temp_file_write_size 64k;
             }
             #设定查看Nginx状态的地址
             location /NginxStatus {
                     stub_status             on;
                     access_log              on;
                     auth_basic              "NginxStatus";
                     auth_basic_user_file  conf/htpasswd;
             }
     }
}
#为什么kernel.shmmax这个要配置成134217728
#默认的不可以吗?你这个数字是怎么计算出来的啊?
#张宴 回复于 2008-9-2 08:49
#因为php.ini中配置了eaccelerator.shm_size="128",允许eaccelerator可使用的共享内存大小为128M。
#而 134217728bytes / 1024 / 1024 = 128MB
#在Linux下,单个进程的最大内存使用量受/proc/sys/kernel/shmmax中设置的数字限制(单位为字节),例如CentOS、 Redhat的shmmax默认值为33554432字节(33554432bytes/1024/1024=32MB)。
#临时更改该值:
#echo 字节数 > /proc/sys/kernel/shmmax
#按照以上方法更改,在每次重启系统时,该值会被自动还原。如果想永久更改,可以修改/etc/sysctl.conf文件,设置:
#kernel.shmmax = 字节数
#如果你的eaccelerator使用默认的32M共享内存,可以不修改此值。



想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-20 21:59

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表