网上找到一个比较详细的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_www.log;
location / {
root html;
index index.jsp index.htm;
proxy_pass http://myserver;
}
location /status {
stub_status on;
access_log off;
auth_basic "status";
auth_basic_user_file /etc/nginx/htpasswd;
}
}
}
以上是一个主机的配置,如果跑虚拟主机就分别在upstream和server下加上相应的配置文件即可。
这里顺便提下日志轮循的问题,默认情况下nginx的日志会自动压缩每天生成一个*.log.gz的格式的日志文件,不利于awstat分析。
于是,我做了简单的处理。
修改/etc/logrotate.d/nginx文件如下
具体请根据自己的情况做相应更改。
附:
log_date_format.sh
并修改/etc/crontab文件
59 23 * * * root run-parts /etc/cron.daily
每天晚上23:59分执行日志轮循。
如上处理之后,会得到类似aaa.test.com.2012-10-10格式的日志,便于使用awstat进行分析。