user www www; #Nginx每个进程耗费10MB~12MB内存,这里只开启一个Nginx进程,节省内存。 worker_processes 1; error_log /data1/logs/nginx_error.log crit; pid /usr/local/webserver/nginx/nginx.pid; #Specifies the value for maximum file descriptors that can be opened by this process. worker_rlimit_nofile 51200; events { use epoll; worker_connections 51200; } 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; 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; #对网页文件、CSS、JS、XML等启动gzip压缩,减少数据传输量,提高访问速度。 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 www.yourdomain.com; index index.html index.htm index.php; root /data0/htdocs/blog; location ~ .*\.(php|php5)?$ { #将Nginx与FastCGI的通信方式由TCP改为Unix Socket。TCP在高并发访问下比Unix Socket稳定,但Unix Socket速度要比TCP快。 fastcgi_pass unix:/tmp/php-cgi.sock; #fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; } #图片更改较少,将它们在浏览器本地缓存15天,可以提高下次打开时的加载速度。 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 15d; } #将JavaScript、CSS它们在浏览器本地缓存1天,访问者在看完一篇文章或一页后,再看另一篇文章或另一页的内容,无须从服务器再次下载相同的JavaScript、CSS,提高了页面显示速度。 location ~ .*\.(js|css)?$ { expires 1d; } log_format access '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" $http_x_forwarded_for'; access_log /data1/logs/access.log access; } }