#user nobody; #运行用户
worker_processes 1; #启动进程,通常设置成和CPU数量相等
#全局错误日志及错误记录类型
#错误类型 [ debug | info | notice | warn | error | crit ] 从左到右 从最详细到最少
#error_log off 并不能关闭日志功能,它会导致nginx将错误日志记录到文件名为 off 的文件中
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid文件是一个纯粹的文本文件,里面记录的是nginx进程的id号
#pid logs/nginx.pid;
events {
# use epoll #epoll 是多路复用IO中的一种方式,但是仅用于Linux 2.6以上内核,可以大大提高nginx性能
worker_connections 1024; #单个后台work process进程的最大并发连接数
#此处联合worker_process 一同决定了最大客户端连接数
}
#设定http服务器,利用它的反响代理功能提供负载均衡
http {
#设定mime类型,类型由mime.types文件定义
include mime.types;
#属于http的核心指令,【当前设定为二进制流】,就是当文件类型未定义的时使用这种方式
default_type application/octet-stream;
#log_format 实现对日志格式的设定
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
#sendfile 指令指定nginx是否调用sendfile函数 | 用于开启高效传输模式【将tcp_nopush和tcp_nodelay两个指令设置为on用于防止网络阻塞】
sendfile on;
#tcp_nopush on;
#tcp_nodely on;
#设置客户端连接保持活动的超时时间,单位 s
#这里涉及一个问题,超时时间设置的比较短的话会导致大文件上传失败,超时时间设置比较长的话会导致无效的链接占据nginx的连接数最终会导致nginx崩溃
#keepalive_timeout 0;
keepalive_timeout 65;
#用于设置开启或者关闭GZIP
#gzip on;
#设置允许压缩的最小字节数
#gzip_min_length 1k;
#此处表示申请4个16K的内存作为压缩结果流缓存,默认值是申请与原始数据大小相同的内存空间来存储gzip压缩结果
#gzip_buffers 4 16k;
#用于设置识别http版本
#gzip_http_version 1.1;
#指定gzip的压缩比
#gzip_comp_level 2;
#用来指定压缩的类型,无论是否指定,text/html类型总是会被压缩的
#gzip_types text/plain application/x-javascript text/css application/xml;
#设置允许前端的缓存服务器可以缓存gzip压缩的页面【例如:squid缓存经过nginx压缩的数据】
#gzip_vary on;
#虚拟主机设置
server {
listen 127.0.0.1;#用于指定虚拟主机的服务端口
server_name localhost;#指定IP地址或域名,多个域名之间用空格分开
#设置网页的默认编码格式
#charset koi8-r;
#指定此虚拟机的访问日志存放路径
#access_log logs/host.access.log main;
#URL匹配配置
#支持正则表达式、条件判断匹配
location / {
#root html;
root d:/wnmp/www;
index index.html index.htm index.php;
#用来指定过期时间
#expires 30
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#对url进行匹配,可以进行重定向或者进行新的代理【负载均衡】
location ~ \.php$ {
root d:/wnmp/www;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME d:/wnmp/www$fastcgi_script_name;
include fastcgi_params;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
include D:/wnmp/nginx/vhostsconf/*;
}
一个虚拟主机的配置:
server {
listen 127.0.0.1;
server_name yafsearch.com;
index index.html index.htm index.php;
root D:/wnmp/yafsearch/yafapp/public_html/;
location /
{
if (!-f $request_filename){
rewrite ^/(.+)$ /index.php?$1& last;
}
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9003;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}