图文详解TCP_IP基础原理和技术电子书pdf下载
#user nobody;
#启动进程,通常设置成和cpu的数量相等
#<--!
#As a general rule you need the only worker with large number of
#worker_connections, say 10,000 or 20,000.
#
#However, if nginx does CPU-intensive work as SSL or gzipping and
#you have 2 or more CPU, then you may set worker_processes to be equal
#to CPU number.
#
#Besides, if you serve many static files and the total size of the files
#is bigger than memory, then you may increase worker_processes to
#utilize a full disk bandwidth.
#
#Igor Sysoev
#
#一般一个进程足够了,你可以把连接数设得很大。如果有SSL、gzip这些比较消耗CPU的工作,而且是多核CPU的话,可以设为和CPU的数量一样。或 者要处理很多很多的小文件,而且文件总大小比内存大很多的时候,也可以把进程数增加,以充分利用IO带宽(主要似乎是IO操作有block)。
#
#根据我配置实践,服务器是“多个CPU+gzip+网站总文件大小大于内存”的环境,worker_processes设置为CPU个数的两倍比较好。
#eg: 2个4核CUP, 则设置为8或者16.
#!-->
worker_processes 1;
#全局错误日志及PID文件
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
#工作模式及连接数上限
events {
use epoll; #epoll是多路复用IO(I/O Multiplexing)中的一种方式,但是仅用于linux2.6以上内核,可以大大提高nginx的性能
worker_connections 1024; #单个后台worker process进程的最大并发链接数
}
#设定http服务器,利用它的反向代理功能提供负载均衡支持
http {
include mime.types; #设定mime类型,类型由mime.type文件定义
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 方式)来输出文件,对于普通应用,必须设为 on,如果
#用来进行下载等应用磁盘IO重负载应用,可设置为 off,以平衡磁盘与网络I/O处理速度,降低系统的uptime.
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65; #连接超时时间
gzip on; #开启gzip压缩
#设定请求缓冲
client_header_buffer_size 1k;
large_client_header_buffers 44k;
#设定负载均衡的服务器列表
upstream mysvr {
#weigth参数表示权值,权值越高被分配到的几率越大
#本机上的Squid开启3128端口
server 192.168.8.1:3128 weight=5;
server 192.168.8.2:80 weight=1;
server 192.168.8.3:80 weight=6;
}
server {
#监听 端口
listen 8014;
#定义使用localhost访问
server_name localhost;
#charset koi8-r;
#设定本虚拟主机的访问日志
#access_log logs/host.access.log main;
#默认请求
location / {
root /program/www/viewimg; #定义服务器的默认网站根目录位置
index index.html index.htm; #定义首页索引文件的名称
}
}
server {
listen 8070;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /StaticResource {
root /data1/dcw;
index index.html index.htm;
}
location /briefData/ {
alias /data1/fastBrief/;
expires -1;
break;
}
location /user_wk/ {
alias /data1/dcw/user_wk/;
expires -1;
break;
}
location /trans/blogimg {
alias /data1/docs/blogimg/;
expires -1;
break;
}
location / {
proxy_pass http://test.dcq.cn:6071/;
client_max_body_size 10m;
#index index.html index.htm;
}
location /nginx_status {
stub_status on;
access_log off;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
#############
server {
listen 8071;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /StaticResource {
root /data1/dcw;
index index.html index.htm;
}
location /briefData/ {
alias /data1/fastBrief/;
expires -1;
break;
}
location /user_wk/ {
alias /data1/dcw/user_wk/;
expires -1;
break;
}
location / {
proxy_pass http://127.0.0.1:6072/;
client_max_body_size 10m;
#index index.html index.htm;
}
location /trans/blogimg {
alias /data1/docs/blogimg/;
expires -1;
break;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
###############
server {
listen 8075;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location /StaticResource {
root /data1/dcw;
index index.html index.htm;
}
location /briefData/ {
alias /data1/fastBrief/;
expires -1;
break;
}
location /user_wk/ {
alias /data1/dcw/user_wk/;
expires -1;
break;
}
location / {
proxy_pass http://test.dcq.cn:6073/;
client_max_body_size 10m;
break;
}
}
###############
# 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 配置说明(nginx.conf)