user www www; // 使用的用户和组 worker_processes 8; // 指定的工作衍生进程数(一般等于cpu总核数或总核数的2倍) error_log logs/nginx_error.log crit; // 指定错误日志存放的路径,错误日志记录级别分别选项为:debug,info,notice,warn,error,crit #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; pid nginx.pid; // 指定pid文件存放的路径 #pid logs/nginx.pid; worker_rlimit_nofile 65535; // 一个nginx进程打开的最多文件描述符数目,理论值是最多打开的文件数(系统ulimit -n)与nginx进程数相除,但是nginx分配请求并不均匀,所以在这里建议和ulimit 值保持一致 events { use epoll; // 使用网络I/O模型,Linux系统推荐采用epoll模型,FreeBSD系统推荐采用kqueue模型 worker_connections 51200; // 允许的连接数 } # 设定http主机,利用它的反向代理功能提供负载均衡支持 http { include mime.types; // 设定mime类型,类型由mime.type文件定义 default_type application/octet-stream; charset utf-8; // 设置使用的字符集,如果一个网站有多种字符集,请不要随便设置,应该让程序员在HTML代码中通过Meta标签设置 ssi on; // 页面静态化的一个大问题是登陆用户访问如果静态化,大部分页面内容需要缓存但是用户登陆的个人信息是动态的,ssi用来解决页面部分缓存问题 ssi_silent_errors on; // 默认是off,开启后在处理SSI文件出错时不输出错误提示:"[an error occurred while processing the directive]" ssi_types text/shtml; // 默认是ssi_types text/html,所以如果需要htm和html支持,则不需要设置这句,如果需要shtml支持,则需要设置 #log_format main '$remote_addr - $remote_user [$time_local] "$request" ' # '$status $body_bytes_sent "$http_referer" ' # '"$http_user_age
# 以下时阿里云主机上的一段nginx.conf配置文件
user www www; worker_processes auto; error_log /alidata/log/nginx/error.log crit; pid /alidata/server/nginx/logs/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 65535; events { use epoll; worker_connections 65535; } http { include mime.types; default_type application/octet-stream; #charset gb2312; server_names_hash_bucket_size 128; client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 8m; sendfile on; tcp_nopush on; keepalive_timeout 15; tcp_nodelay on; fastcgi_connect_timeout 300; fastcgi_send_timeout 300; fastcgi_read_timeout 300; fastcgi_buffer_size 64k; fastcgi_buffers 4 64k; fastcgi_busy_buffers_size 128k; fastcgi_temp_file_write_size 128k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 2; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; gzip_disable msie6; #limit_zone crawler $binary_remote_addr 10m; log_format '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_age