nginx配置

跳转nginx官方文档

 

#运行用户.在windows下无效
#user nobody;

#工作进程 在实际运用时,通常设置成与CPU数量相等
worker_processes 1;

#全局错误日志
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#PID文件
#pid logs/nginx.pid;

#工作模式及连接数上限
events {
#epoll是多路复用IO中的一种方式
#仅用于linux2.6以上内核,可以大大提高nginx的性能
#use epoll

#单个后台worker process进行的最大并发链接数
worker_connections 1024;

#并发总数是worker_process和worker_connections的乘积
#即max_clients = worker_processes * worker_connections
#在设置了反向代理的情况下, max_clients = worker_processes * worker_connections/4
#为什么在设置了反向代理要除以4,应该说是一个经验值(这里的4不一定正确,需要详细了解反向代理的工作原理才能做最后的确定)
#worker_connections值的设置跟物理内存有关
#因为并发受IO约束,max_clients的值必须小于系统可以打开的最大文件数
#而系统可以打开的最大文件数和内存大小成正比.一般1GB内存的机器上可以打开的文件数大约是10万左右
#linux系统查看可以打开的最大文件数的命令:
#cat /proc/sys/fs/file-max
}


http {
#设定mime类型 类型由mime.type文件定义
include mime.types;
default_type application/octet-stream;

#设定日志格式
#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函数(zero copy方式.只在linux下有效.因为linux在底层支持了sendfile函数)来输出文件
#对于普通应用,必须设置为on
#如果用来进行下载等应用磁盘IO重负载应用,可设置为off以平衡磁盘与网络I/O处理速度,降低系统的uptime
sendfile on;
#tcp_nopush只有在启用sendfile情况下才有效. tcp_nopush与tcp_nodelay是互斥的.两者共同决定Nagle算法是否生效
#tcp_nopush on;

#链接超时时间
#keepalive_timeout 0;
keepalive_timeout 65;
#tcp_nodelay on;

#允许客户端请求的最大单文件字节数(在有上传文件需求时需要注意该配置,总上传的文件大小超过这个设置值会导致请求直接被终止)
#client_max_body_size 100M;
#客户端请求使用的缓冲区大小
#client_body_buffer_size 128k;

#开启zip压缩 gzip压缩功能可以节省带宽但会增加服务器CPU的开销

#gzip on;
#gzip_http_version 1.0;
#对IE1~6压缩不起作用
#gzip_disable "MSIE[1-6]";
#设置可压缩的内容 默认只对text/html进行压缩
#gzip_types text/plain application/x-javascript text/css text/javascript application/x-httpd-php image/jpeg image/gif image/png;
#nginx做前端代理使用,表示无论后端服务器的headers头返回什么信息,都无条件启用压缩
#gzip_proxied any;
#最小压缩的页面 如果页面过小,可能会越压越大,这里规定大于1K的页面才启用压缩
#gzip_min_length 1024;
#设置系统获取几个单位的缓存用于存储gzip的压缩结果数据流
#gzip_buffers 4 8K;
#压缩级别 1~9 从小到大,压缩比变大但处理速度变慢 一般设置为3就可以
#gzip_comp_level 3;

#设定请求缓冲.该参数也可同时在server中设置,
#但在server中设置的值,只有低于nginx主配置中的值才有意义,
#否则那些有巨大header的请求,依然会受到主配置中large_client_header_buffers的限制
#nginx默认会用client_header_buffer_size这个buffer来读取header值,
#如果header过大,它就会使用large_client_header_buffers来读取
#client_header_buffer_size 128k;
#large_client_header_buffers 4 128K;

server {
#侦听端口
listen 80;
#定义使用localhost访问
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;
#location的语法规则:
#location [=|~|~*|^~] /uri/ {...}
#location @name {...}
#第一种用法的含义:
# =开头表示精确匹配
# ^~开头表示URI以某个常规字符串开头.理解为匹配url路径即可
# ~开头表示区分大小写的正则匹配
# ~*开头表示不区分大小写的正则匹配
# !~和!~*表示区分大小写及不区分大小写不匹配的正则
# /开头通用匹配,任何请求都会匹配到
#多个location配置的匹配顺序:
#首先匹配=,其次匹配^~,其次是按文件中顺序的正则匹配,最后是/的通用匹配
#第二种用法的含义:
# @用来定义Named Location的.这种Named Location不是用来处理普通的HTTP请求,它是专门用来处理"内部重定向"请求,是服务端的一个转发行为
location / {
#定义服务器的默认网站根目录位置
root html;
#定义首页索引文件的名称
index index.html index.htm;
}

#定义错误号对应的提示页面
#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;
}
#location @的用法
#error_page 404 http://www.baidu.com #直接这样是不被允许的
#error_page 404 = @fallback #当发现URI对应的页面不存在,此时就会转到fallback的location中,进而转到www.baidu.com页面
#location @fallback{
# proxy_pass http://www.baidu.com;
#}

#PHP脚本请求全部转发到Apache中
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

#PHP脚本请求全部转发到FastCGI处理.使用FastCGI默认配置
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location定义文件类型 \.php表示所有以php作为文件后缀的文件类型
#location ~ \.php$ {
#root 定义php文件存放路径(这里最好设置绝对路径,否则可能会由于寻址路径原因导致php崩溃)
# root html;
#定义php-cgi的连接地址
# fastcgi_pass 127.0.0.1:9000;
#定义php文件类型中的默认索引页
# fastcgi_index index.php;
#定义页面请求参数
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
#定义fastcgi配置信息将会被保存到nginx/conf/fastcgi_params文件中
# include fastcgi_params;
#}

#禁止访问.htxxx文件
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

#配置虚拟主机(virtual host)
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;

# location / {
# root html;
# index index.html index.htm;
# }
#}


#启用HTTPS访问的配置
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;

# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;

# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;

# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;

# location / {
# root html;
# index index.html index.htm;
# }
#}

}

posted on 2016-03-11 10:33  学习与成神之路  阅读(171)  评论(0编辑  收藏  举报

导航