Nginx 配置管理

A: 基本配置

--------------- START -----------------
worker_processes 10;

error_log logs/error.log error;

pid logs/nginx.pid;

worker_rlimit_nofile 51200;

events {
use epoll;
worker_connections 51200;
}


http {
include mime.types;
default_type application/octet-stream;

log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

access_log logs/access.log main;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
gzip on;
gzip_min_length 1100;
gzip_buffers 4 8k;
gzip_types text/* text/css application/x-javascript;
output_buffers 1 512k;
gzip_comp_level 9;
postpone_output 1460;

upstream mysvr{
server 127.0.0.1:8080;
}


server {
listen 80;
server_name localhost;

charset utf-8;

access_log logs/host.access.log main;

location / {
proxy_pass http://mysvr;

proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_read_timeout 5;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;

}


location ~* \.(jpg|jpeg|png|html|bmp|gif|js|css)$ {
root /usr/gsims/webapp/jboss-5.1.0.GA/server/default/deploy/ROOT.war;
expires 30d;
}


location = /50x.html {
root html;
}
}

}
---------------- END -----------

nginx ,错误日志不停报以下错误:
[引用]http://hi.baidu.com/liheng_2009/blog/item/e760d11947b325158718bf01.html


2010/05/26 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
2010/05/26 08:53:49 [alert] 13576#0: accept() failed (24: Too many open files)
解决方法:

centos5.3 中 ulimit -n 为1024, 当Nginx连接数超过1024时,error.log中就出现以下错误:

[alert] 12766#0: accept() failed (24: Too many open files)

使用 ulimit -n 655350 可以把打开文件数设置足够大, 同时修改nginx.conf , 添加 worker_rlimit_nofile 655350; (与error_log同级别)

这样就可以解决Nginx连接过多的问题,Nginx就可以支持高并发。

另外, ulimit -n 还会影响到mysql 的并发连接数。把他提高,也就提高了mysql并发。

注意: 用ulimit -n 2048 修改只对当前的shell有效,退出后失效。

修改方法

若要令修改ulimits的数值永久生效,则必须修改配置文档,可以给ulimit修改命令放入/etc/profile里面,这个方法实在是不方便,

还有一个方法是修改/etc/security/limits.conf

/etc/security/limits.conf 格式,文件里面有很详细的注释,比如

* soft nofile 655360

* hard nofile 655360

星号代表全局, soft为软件,hard为硬件,nofile为这里指可打开文件数。

把以上两行内容加到 limits.conf文件中即可。

另外,要使 limits.conf 文件配置生效,必须要确保 pam_limits.so 文件被加入到启动文件中。查看 /etc/pam.d/login 文件中有:

session required /lib/security/pam_limits.so

修改完重新登录就可以见到效果,可以通过 ulimit -n 查看。

参考:

http://gfllove.blog.163.com/blog/static/1515027200923010653628/

http://loamy.iteye.com/blog/380150
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值