nginx配置文件nginx.conf
2015-09-11 16:47
579 查看
#定义Nginx运行的用户和用户组 user root root; #user nobody; #定义了nginx对外提供web服务时的worker进程数。最优值取决于许多因素,包括(但不限于)CPU核的数量、存储数据的硬盘数量 #及负载模式。不能确定的时候,将其设置为可用的CPU内核数将是一个好的开始(设置为“auto”将尝试自动检测它)。 worker_processes 3; #全局错误日志定义类型,[ debug | info | notice | warn | error | crit ] error_log /usr/local/nginx/logs/error.log; error_log /usr/local/nginx/logs/error.log notice; error_log /usr/local/nginx/logs/error.log info; pid /usr/local/nginx/logs/nginx.pid; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; #工作模式与连接数上限 events { #单个进程最大连接数(最大连接数=连接数*进程数) worker_connections 1024; } #设定http服务器,利用它的反向代理功能提供负载均衡支持 http { #文件扩展名与文件类型映射表 include mime.types; #默认文件类型 default_type application/octet-stream; #服务器名字的hash表大小 server_names_hash_bucket_size 128; #设定请求缓冲 client_header_buffer_size 32k; large_client_header_buffers 4 32k; client_max_body_size 50m; #设定日志格 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 /usr/local/nginx/logs/access.log main; #设定负载均衡的服务器列表,weight是权重,可以根据机器配置定义权重。 #weigth参数表示权值,权值越高被分配到的几率越大。 upstream server_group1{ server 20.10.81.101:80; } #开启高效文件传输模式,sendfile指令指定nginx是否调用sendfile函数来输出文件,对于普通应用设为 on, #如果用来进行下载等应用磁盘IO重负载应用,可设置为off,以平衡磁盘与网络I/O处理速度,降低系统的负载。 #注意:如果图片显示不正常把这个改成off。 sendfile on; #tcp_nopush on; #长连接超时时间,单位是秒 #keepalive_timeout 0; keepalive_timeout 65; #gzip模块设置 #gzip on; #虚拟主机的配置 server { #监听端口 listen 80; #域名可以有多个,用空格隔开 server_name localhost.localdomain; #charset koi8-r; access_log off; #对请求到/group1/M00路径上的请求处理 #这个是根据我自己做Fastdfs分布式文件系统做的配置 #这里是对nginx和fastdfs-nginx-module的整合 #FastDFS通过Tracker服务器,将文件放在Storage服务器存储,但是同组之间的服务器需要复制文件,有延迟的问题 #假设Tracker服务器将文件上传到了192.168.1.80,文件ID已经返回客户端,这时,后台会将这个文件复制到192.168.1.30, #如果复制没有完成,客户端就用这个ID在192.168.1.30取文件,肯定会出现错误 #这个fastdfs-nginx-module可以重定向连接到源服务器取文件,避免客户端由于复制延迟的问题出现错误 #下面的这个配置就是使用nginx的扩展模块fastdfs-nginx-module模块 location /group1/M00 { root /usr/local/src/fastdfs/storage/data; ngx_fastdfs_module; } # 定义错误提示页面 #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; } #PHP 脚本请求转发配置 # 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 # #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; #} # 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 # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # 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; # } #} }
相关文章推荐
- nginx+FastDFS+fastdfs-nginx-module配置分布式文件存储
- 高性能web服务器nginx(二)之常用功能举例
- Nginx负载均衡配置(实现多台主机应用负载均衡并且隐藏应用主机不受攻击)
- Nginx 下缓存静态文件(如css js)
- 阿里云服务器cent0S安装web环境PHP+MySql+Nginx,给nginx添加网站
- Nginx和LVS概述
- nginx之基础命令(压缩、自动列目录、浏览器本地缓存)
- Nginx+Lua+GraphicsMagick实现动态生成指定尺寸的图片
- nginx之基础命令(日志分析)
- lnmp配置nginx
- Nginx限制带宽配置示例
- nginx 高并发配置参数(转载)
- Nginx配置upstream实现负载均衡
- ubuntu nginx configure 需要额外安装的库
- ubuntu下配置nginx+php+mysql详解
- centos/rhel下实现nginx自启动脚本实例
- centos下nginx启动脚本和chkconfig管理
- 1.7-nginx用户认证
- windows 下nginx和php的配置
- nginx优化