一个比较详细的nginx配置文件
研究nginx有段时间了,下面帖个比较详细的nginx的配置文件,大家参考下吧,也许有不足。
user nobody;
worker_processes 8;
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log /var/log/nginx/error.log info;
pid /var/log/nginx/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 30000;
}
http {
include /etc/nginx/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"';
server_names_hash_max_size 256;
server_names_hash_bucket_size 512;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
client_max_body_size 1m;
client_body_buffer_size 128k;
client_header_timeout 60;
client_body_timeout 60;
client_body_temp_path /var/lib/nginx/tmp/client_body 1 2;
gzip on;
gzip_min_length 1024;
gzip_buffers 4 8k;
gzip_comp_level 9;
gzip_types text/plain text/html image/x-icon;
output_buffers 1 512k;
postpone_output 1460;
send_timeout 60;
sendfile off;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 60;
upstream myserver {
ip_hash;
server ip:1580;
server ip:1580;
server ip:1580;
server ip:1580;
}
server {
listen 80;
server_name www.*****.com;
charset utf-8;
access_log /var/log/nginx/www.*****.com.log;
error_log /var/log/nginx/error_
location / {
root html;
index index.jsp index.htm;
proxy_pass
}
location /status {
stub_status on;
access_log off;
auth_basic "status";
auth_basic_user_file /etc/nginx/htpasswd;
}
}
}
以上是一个主机的配置,如果跑虚拟主机就分别在upstream和server下加上相应的配置文件,就ok了。这里顺便提下日志轮训的问题,默认情况下nginx的日志会自动压缩每天生成一个*.log.gz的格式的日志文件,不利于awstat分析,于是我简单的处理了下。
修改/etc/logrotate.d/nginx文件如下
daily
rotate 31
missingok
notifempty
create
sharedscripts
postrotate
[ ! -f /var/log/nginx/nginx.pid ] || kill -USR1 `cat /var/log/nginx/nginx.pid`
sh /root/log_date_format.sh
endscript
}
具体情况做相应更改。
附上log_date_format.sh文件
#!/bin/bash
date=`date +%Y-%m-%d`
log_dir=/var/log/nginx
for i in aaa bbb ccc;
do mv ${log_dir}/$i.test.com.log.1 ${log_dir}/$i.test.com.log.$date;
done
并修改/etc/crontab文件
59 23 * * * root run-parts /etc/cron.daily
每天晚上23:59分执行日志轮训
这样处理后就会得到类似aaa.test.com.2008-10-10这样格式的日志,便于awstat分析。
阅读(1157) | 评论(0) | 转发(0) |