1.nginx.conf为nginx的主配置文件,常用的配置如下:
user www www ;
worker_processes 4;
error_log logs/error.log;
pid logs/nginx.pid;
worker_rlimit_nofile 65535;
events {
use epoll;
worker_connections 65535;
}
http {
include mime.types;
default_type application/octet-stream;
#charset utf-8;
access_log logs/access.log ;
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 60;
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.0;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
server {
listen 80;
server_name localhost;
index index.html index.htm index.php;
root /opt/nginx/html ;
access_log logs/host.access.log ;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 1h;
}
}
}
2.配置文件详解
user www www ; 指定nginx worker进程运行的用户和组
worker_processes 4; 指定nginx要开启的进程数,每个进程消耗10M左右,一般设置为和cpu个数一样
error_log logs/error.log; 定义全局错误日志文件
pid logs/nginx.pid; 存储进程id的文件位置
worker_rlimit_nofile 65535; 允许打开的最大文件数
events {
use epoll; 指定nginx的工作模式
worker_connections 65535; 指定nginx的每个进程的最大连接数
}
http {
include mime.types;
default_type application/octet-stream; 设定文档的默认类型为二进制流,当文档的类型未设定时使用这种方式
#charset utf-8; 设定默认字符类型
access_log logs/access.log ;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k; 指定客户端请求头的headbuffer大小
large_client_header_buffers 4 32k; 设置客户端请求支中较大的消息头的缓存最大数量和大小,4为个数,32为大小
client_max_body_size 8m; 设置允许客户端请求的最大单个文件字节数
sendfile on; 用于开启高效文件传输模式
tcp_nopush on;
tcp_nodelay on; 这两个参数设置为on,用于防止网络阻塞。
keepalive_timeout 60; 设置客户端连接保持活动的超时时间,如果超过这个时间客户端还没发送任何数据,nginx将返回408的错误