nginx.conf 配置解释

详解user   www www;
定义 Nginx 运行的用户及组
worker_processes 8; #[ debug | info | notice | warn | error | crit ]
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 65535;
一个 nginx 进程打开的多文件描述符数目,理论值应该是多打开文件数(ulimit
-n) nginx 进程数相除,与但是 nginx 分配请求并不是那么均匀,所以好与 ulimit -n的值保持一致。
# use [ kqueue | rtsig | epoll | /dev/poll | select | poll ];
events use epoll; 参考事件模型
worker_connections 65535; 每个进程大连接数(大连接=连接数 x 进程数) #设定 http 服务器
http include
mime.types; 文件扩展名与文件类型映射表
default_type application/octet-stream; #默认文件类型
#charset gb2312; 默认编码
server_names_hash_bucket_size 128; #服务器名字的 hash 表大小
client_header_buffer_size 32k; 上传文件大小限制
large_client_header_buffers 4 32k; 设定请求缓
client_max_body_size 8m; 设定请求缓
sendfile on; #开启高效文件传输模式
tcp_nopush
on; 防止网络阻塞
tcp_nodelay on; 防止网络阻塞
keepalive_timeout 60; 超时时间
#FastCGI 是为了改善网站的性能--减少资源占用,提高访问速度.有关 fastCGI 的
详细资料请参阅:http://www.fastcgi.com
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;
#压缩版本(默认 1.1,前端为 squid2.5 使用 1.0
gzip_comp_level 2; 压缩等级
gzip_types
text/plain application/x-javascript text/css application/xml;
压缩类型,默认已经包含 text/html 所以下面不用再写了,当然写上去的话,也
不会有问题,但是会有一个 warn
gzip_vary on;
#limit_zone crawler $binary_remote_addr 10m; server listen   80;
server_name www.opendoc.com.cn
index index.html index.htm index.php;
root /data0/htdocs/opendoc;
location ~ .*.(php|php5)?$ #fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf; #对图片缓存
location ~ .*.(gif|jpg|jpeg|png|bmp|swf)$ expires 30d; #对 JS CSS 缓存
location ~ .*.(js|css)?$ expires  1h; #日志设定
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;
}
 

  nginx判断手机移动设备用户的方法

  有两种方法

  一种是用语言进行判断,比如用php的 $_SERVER['User-Agent']

php
 
function is_mobile(){
 
    // returns true if one of the specified mobile browsers is detected
 
    $regex_match="/(nokia|iphone|android|motorola|^mot-|softbank|foma|docomo
 |kddi|up.browser|up.link|";
    $regex_match.="htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos
 |techfaith|palmsource|";
    $regex_match.="blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam-|s[cg]h|^lge|ericsson
 |philips|sagem|wellcom|bunjalloo|maui|";    
    $regex_match.="symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte-
 |longcos|pantech|gionee|^sie-|portalmmm|";
    $regex_match.="jigs browser|hiptop|^ucweb|^benq|haier|^lct|operas*mobi
 |opera*mini|320x320|240x320|176x220";
    $regex_match.=")/i";        
    return isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE']) or preg_match($regex_match,strtolower($_SERVER['HTTP_USER_AGENT']));
}
 
/*
allow the user a way to force either the full or mobile versions of the site - use a GET parameter on requests:
 
include likes to both versions of the site w/ the special force mode parameters, 'mobile' and 'full':
 
View Mobile Sitea>
View Full Sitea>
 
Always check for 'mobile' or 'full' parameters before accounting for any User-Agent conditions:
*/
 
if ($_GET['mobile']) {
 $is_mobile = true;
}
 
if ($_GET['full']) {
 $is_mobile = false;
}
if($is_mobile) {
    //it's a mobile browser, do something
    header("Location: http://wap.baidu.com");
} else {
    //it's not a mobile browser, do something else
    header("Location: http://www.baidu.com");
    // or instead of a redirect, simply build html below
}
 
?>