#工做进程数,建议设置为CPU的总核数 worker_processes 2; #全局错误日志定义类型,日志等级从低到高依次为: #debug | info | notice | warn | error | crit error_log logs/error.log info; #记录主进程ID的文件 pid /nginx/nginx.pid; #一个进程能打开的文件描述符最大值,理论上该值因该是最多能打开的文件数除以进程数。 #可是因为nginx负载并非彻底均衡的,因此这个值最好等于最多能打开的文件数。 #LINUX系统能够执行 sysctl -a | grep fs.file 能够看到linux文件描述符。 worker_rlimit_nofile 65535; #链接数上限, 单个进程容许的最大链接数 events { worker_connections 65535; } #设定http服务器,利用它的反向代理功能提供负载均衡支持 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 记录了哪些用户,哪些页面以及用户浏览器、ip和其余的访问信息 access_log logs/access.log main; #服务器名字的hash表大小 server_names_hash_bucket_size 128; #客户端请求头缓冲大小。 #nginx默认会用client_header_buffer_size这个buffer来读取header值, #若是header过大,它会使用large_client_header_buffers来读取。 #若是设置太小HTTP头/Cookie过大 会报400 错误 nginx 400 bad request #若是超过buffer,就会报HTTP 414错误(URI Too Long) #nginx接受最长的HTTP头部大小必须比其中一个buffer大 #不然就会报400的HTTP错误(Bad Request) client_header_buffer_size 32k; large_client_header_buffers 4 32k; #客户端请求体的大小 client_body_buffer_size 8m; #隐藏ngnix版本号 server_tokens off; #忽略不合法的请求头 ignore_invalid_headers on; #指定启用除第一条error_page指令之外其余的error_page。 recursive_error_pages on; #让 nginx 在处理本身内部重定向时不默认使用 server_name 设置中的第一个域名 server_name_in_redirect off; #开启文件传输,通常应用都应设置为on;如果有下载的应用,则能够设置成off来平衡网络I/O和磁盘的I/O来下降系统负载 sendfile on; #告诉nginx在一个数据包里发送全部头文件,而不一个接一个的发送。 tcp_nopush on; #告诉nginx不要缓存数据,而是一段一段的发送--当须要及时发送数据时,就应该给应用设置这个属性,这样发送一小块数据信息时就不能当即获得返回值。 tcp_nodelay on; #长链接超时时间,单位是秒 keepalive_timeout 65; #gzip模块设置,使用 gzip 压缩能够下降网站带宽消耗,同时提高访问速度。 gzip on;#开启gzip gzip_min_length 1k; #最小压缩大小 gzip_buffers 4 16k; #压缩缓冲区 gzip_http_version 1.0; #压缩版本 gzip_comp_level 2; #压缩等级 gzip_types text/plain application/x-javascript text/css application/xml; #压缩类型 #upstream做负载均衡,在此配置须要轮询的服务器地址和端口号,max_fails为容许请求失败的次数,默认为1. #weight为轮询权重,根据不一样的权重分配能够用来平衡服务器的访问率。 #指定要域名对应的WEB项目访问地址 upstream hostname { server 192.168.33.129:18080 max_fails=0 weight=1; } #主机配置 server { #监听端口 listen 80; #本身指定要跳转的域名 server_name youjie.co; #字符集 charset utf-8; #单独的access_log文件 access_log logs/192.168.33.129.access.log main; #反向代理配置, #将全部请求为http://hostname的请求所有转发到upstream中定义的目标服务器中。 location / { #此处配置的域名必须与upstream的域名一致,才能转发。 proxy_pass http://hostname; proxy_set_header X-Real-IP $remote_addr; } #启用nginx status 监听页面 location /nginxstatus { stub_status on; access_log on; } #错误页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } upstream hostname1 { server 192.168.33.129:28080 max_fails=0 weight=1; } server { #监听端口 listen 80; #本身指定要访问的域名 server_name u-pai.cn; #字符集 charset utf-8; #单独的access_log文件 access_log logs/192.168.33.129.access.log main; #反向代理配置, #将全部请求为http://hostname1的请求所有转发到upstream中定义的目标服务器中。 location / { #此处配置的域名必须与upstream的域名一致,才能转发。 proxy_pass http://hostname1; proxy_set_header X-Real-IP $remote_addr; } #启用nginx status 监听页面 location /nginxstatus { stub_status on; access_log on; } #错误页面 error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } }
代理MySQLjavascript
#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; } stream { upstream mysql { hash $remote_addr consistent; server 127.0.0.1:3306 max_fails=3 fail_timeout=30s; } server { listen 3307; proxy_connect_timeout 30s; proxy_timeout 600s; proxy_pass mysql; } }