#user nobody; worker_processes 1; #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 { 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 on; #tcp_nopush on; #keepalive_timeout 0; keepalive_timeout 65; #gzip on; server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; 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; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } }
#user nobody; worker_processes 1; #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 { server { ... } }
server:用于配置虚拟主机,一个http代码段中,可以包含多个server指令,配置多个虚拟主机
http { upstream mysvr { server 192.168.8.1x:80 weight=5; server 192.168.8.2x:80 weight=1; server 192.168.8.3x:80 weight=6; } server { ... location / { proxy_pass http://mysvr } ... } }
upstream:NGINX负载均衡
2、NGINX如何选择SERVER虚拟主机
NGINX将进入的HTTP请求头与NGINX配置文件中各个server区段比较,并且选择第一个被匹配的server区段
匹配过程按如下流程处理:
1、全域名,静态域名匹配
2、开始部分使用通配符的域名,如:*.xxx.com
3、结尾部分使用通配符的域名,如:www.xxx.*
4、带有正则表达式的域名
如果还没有找到匹配的域名,继续按下面的顺序在配置文件中选择一个server:
1、匹配listen指令被标记为[default|default_server]的区段
2、匹配listen指令(或隐含有listen 80)的第一个server区段
原文地址:http://blog.csdn.net/tianyaz/article/details/43427901