您的位置:首页 > 运维架构 > Nginx

Nginx配置文件详解

2015-08-13 15:11 134 查看
[root@server1 sbin]# vim /usr/local/nginx/conf/nginx.conf
user
nobody;
//定义nginx运行的用户和组
worker_processes
1;
//nginx进程数,建议设置为等于cpu总核心数
error_log
logs/error.log;
//全局错误日志定义的类型 [ debug | info | notice | warn | error ]
pid
logs/nginx.pid;
//进程pid文件
events {

worker_connections
1024;
//单个进程最大的连接数
}
//设置http服务器,作为反向代理功能提供负载均衡
http {

include
mime.types;

default_type
application/octet-stream;
//默认文件类型

sendfile
on;
//开启高效文件传输模式,sendfile指令nginx是否调用sendfile用来输出文件,对普通文件可以设为on,但如果用来下载应用磁盘I/O重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度

#tcp_nopush
on; //防止网络阻塞

keepalive_timeout
65;
//连接超时时间超过65秒则断开连接

#gzip
on;
//开启gzip压缩

//设置负载均衡的服务器列表
upstream
westos {
server
172.25.16.1 weight=3;
server
172.25.16.2 weight=1;

}

//虚拟主机的配置
server
{

listen
80;

server_name
localhost;
//域名可以有多个,用空格隔开

//默认请求

location / {

root
html;
//定义服务器默认访问站点目录

index index.html
index.html; //索引文件的名称

}

//定义错误提示页面

error_page 500 502 503
504 /50x.html;

location = /50x.html {

root html;

}

//对php后缀结尾的文件请求采用负载均衡请求

location ~ \.php$ {

proxy_pass
westos;
//将请求转向westos定义的服务器列表

}

//php脚本请求全部处理转发到FastCGI处理

location ~ \.php$ {

root
html;

fastcgi_pass
127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME
/scripts$fastcgi_script_name;

include
fastcgi_params;

}

//禁止访问.htxx文件

location ~ /\.ht {

deny all;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息