[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;
}
}
php