#nginx配置文件全局配置块
#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;
#evens块主要影响nginx服务器与用户网络的连接,常用的设置包括是否开启对多work process下的网络连接进行序列化,是否允许同时接收多个网络连接,选取那种
#事件驱动模型来处理连接请求,每个work process可以同时支持的最大连接数,下面支持的最大连接数为1024个。可以根据实际情况灵活配置,对nginx性能影响较大
#connection:连接的意思
events {
worker_connections 1024;
}
#http包括二部分,http全局块配置指令包括文件引入,MIME-TYPE定义,日志自定义,连接超时时间,单连接请求上限等
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;
#负载均衡服务列表配置
upstream myserver{
ip_hash;
server 192.168.81.11:8080 weight=1;
server 192.168.80.23:8081 weight=1;
}
#分配服务器策略
#轮询(默认):每个请求按照时间顺序逐一分配到不同的后端服务器,如果后端服务器down掉,能自动剔除
#weight:表示权重,默认为1,设定每个访客固定访问一个后端服务器
#ip_hash:每个请求按ip的hash结果分配,每个访客固定访问一个后端服务器
#fair:按后端服务器的响应时间分配请求,相应时间短优先分配
#server与虚拟主机有密切关系,http块可以包含多个server块,而每一个server块相当于一个虚拟主机
#每个server块也分为全局server块,以及可以同时包括多个location块
#全局server配置本虚拟机的监听配置和本虚拟机的名称以及IP配置
#location块:一个server可以包含多个location,主要作用是基于nginx服务器接收到的请求字符串对虚拟机名称之外的
#字符串进行匹配,对特定的请求进行处理,地址定向,数据缓存和应答控制等
server {
listen 80;
server_name localhost;
server_name 192.168.81.11;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
proxy_pass http://192.168.81.11:8080;
index index.html index.htm;
}
#动静分离
#location /xx/ {
# root /data/;
# autoindex on;
#}
#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;
}
# 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;
# }
#}
}