user www www;
worker_processes 8;
error_log /data1/logs/nginx_error.log crit;
pid /usr/local/webserver/nginx/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
}
http
{
include mime.types;
default_type application/octet-stream;
#charset utf-8;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
sendfile on;
#tcp_nopush on;
keepalive_timeout 30;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/x-javascript text/css application/xml;
gzip_vary on;
limit_zone anti_attack $binary_remote_addr 10m;
#允许客户端请求的最大的单个文件字节数
client_max_body_size 300m;
#缓冲区代理缓冲用户端请求的最大字节数 可以理解为先保存到本地再传给用户
client_body_buffer_size 128k;
#跟后端服务器连接的超时时间_发起握手等候响应超时时间
proxy_connect_timeout 600;
#连接成功后_等候后端服务器响应时间_其实已经进入后端的排队之中等候处理
proxy_read_timeout 600;
#后端服务器数据回传时间_就是在规定时间之内后端服务器必须传完所有的数据
proxy_send_timeout 600;
#代理请求缓存区_这个缓存区间会保存用户的头信息以供Nginx进行规则处理_一般只要能保存下头信息即可
proxy_buffer_size 16k;
#同上 告诉Nginx保存单个用的几个Buffer 最大用多大空间
proxy_buffers 4 32k;
#如果系统很忙的时候可以申请更大的proxy_buffers 官方推荐*2
proxy_busy_buffers_size 64k;
#proxy缓存临时文件的大小
proxy_temp_file_write_size 64k;
#缓存
proxy_temp_path /data2/proxy_temp_path;
proxy_cache_path /data2/proxy_cache_path levels=1:2 keys_zone=cache_one:2000m inactive=1d max_size=5m;
upstream my_server_pool {
server xx.xx.xx.1:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.2:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.3:80 weight=1 max_fails=2 fail_timeout=30s;
}
upstream php_server_pool {
server xx.xx.xx.4:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.5:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.6:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.7:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.8:80 weight=1 max_fails=2 fail_timeout=30s;
}
upstream bbs_server_pool {
ip_hash;
server xx.xx.xx.9:80 max_fails=2 fail_timeout=30s;
server xx.xx.xx.10:80 max_fails=2 fail_timeout=30s;
server xx.xx.xx.11:80 max_fails=2 fail_timeout=30s;
server xx.xx.xx.12:80 max_fails=2 fail_timeout=30s;
}
upstream cms_server_pool {
server xx.xx.xx.13:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.14:80 weight=1 max_fails=2 fail_timeout=30s;
}
upstream pic_server_pool {
server xx.xx.xx.15:80 weight=1 max_fails=2 fail_timeout=30s;
server xx.xx.xx.16:80 weight=1 max_fails=2 fail_timeout=30s;
}
upstream xoyohimsg_server_pool {
server xx.xx.xx.17:3245;
server xx.xx.xx.18:3245 down;
}
#xoyo.com域名跳转到www.xoyo.com
server
{
listen 80;
server_name xoyo.com;
rewrite ^/(.*) http://www.xoyo.com/ permanent;
access_log /data1/logs/xoyo.com_access.log;
}
#用户中心HTTPS/SSL加密浏览
server
{
listen 443;
server_name my.xoyo.com;
ssl on;
ssl_certificate my.xoyo.com.crt;
ssl_certificate_key my.xoyo.com.key;
location /
{
proxy_pass http://php_server_pool;
proxy_set_header Host my.xoyo.com;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log /data1/logs/my.xoyo.com_access.log;
}
#图片服务器,不同的路径访问后端不同的服务器
server
{
listen 80;
server_name pic.xoyo.com;
location /cms/
{
proxy_pass http://cms_server_pool;
proxy_set_header Host pic.xoyo.com;
proxy_set_header X-Forwarded-For $remote_addr;
}
location /
{
proxy_pass http://pic_server_pool;
proxy_set_header Host pic.xoyo.com;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log /data1/logs/pic.xoyo.com_access.log;
}
#音频电台文件下载,进行简单防盗链
#limit_zone media $binary_remote_addr 10m;
server
{
listen 80;
server_name media.xoyo.com;
location /
{
proxy_pass http://cms_server_pool;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
valid_referers none blocked www.xoyo.com *.xoyo.com www.kingsoft.com *.kingsoft.com www.kingsoft.cn *.kingsoft.cn;
if ($invalid_referer) {
rewrite ^/ http://www.xoyo.com;
}
}
access_log /data1/logs/media.xoyo.com_access.log;
}
#逍遥有聊负载均衡,反向代理两种HTTP服务器
server
{
listen 80;
server_name hi.xoyo.com;
#反向代理一款定制开发的高性能消息队列HTTP服务器
location /recmessage.xoyo
{
proxy_pass http://xoyohimsg_server_pool;
proxy_set_header Host $host;
}
location /
{
proxy_pass http://php_server_pool;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log /data1/logs/hi.xoyo.com_access.log;
}
#论坛负载均衡,并对图片、Flash、JavaScript、CSS、静态HTML进行Web缓存
server{
listen 80;
server_name bbs.xoyo.com *.bbs.xoyo.com bbs.xoyo.kingsoft.com;
location /
{
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://bbs_server_pool;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|html|shtml)$
{
proxy_cache cache_one;
proxy_cache_valid 200 10m;
proxy_cache_valid 304 1m;
proxy_cache_valid 301 302 1h;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://bbs_server_pool;
}
log_format bbs '$remote_addr $host $remote_user [$time_local] "$request"'
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log /data1/logs/bbs.xoyo.com_access.log bbs;
}
#论坛附件反向代理,限制下载速度为256KB/秒
server{
listen 80;
server_name att03.bbs.xoyo.com att02.bbs.xoyo.com att01.bbs.xoyo.com;
location /
{
#限制下载速度为256kB/秒
limit_rate 256k;
proxy_pass http://xx.xx.xx.19;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log off;
}
#逍遥江湖SNS社区,管理后台定位到一台服务器上,并对图片、Flash、JavaScript、CSS进行Web缓存区
server{
listen 80;
server_name hu.xoyo.com *.hu.xoyo.com;
location /
{
proxy_pass http://php_server_pool;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
{
proxy_cache cache_one;
proxy_cache_valid 200 10m;
proxy_cache_valid 304 1m;
proxy_cache_valid 301 302 1h;
proxy_cache_valid any 1m;
proxy_cache_key $host$uri$is_args$args;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://php_server_pool;
}
location ~ ^/admincp.php
{
#管理后台定位到一台服务器上
proxy_pass http://xx.xx.xx.4;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
}
access_log /data1/logs/hu.xoyo.com_access.log;
}
}
分享到:
相关推荐
它具有稳定性、丰富的功能集、示例配置文件和低系统资源的消耗,而闻名于俄罗斯最大的门户网站 Rambler Media 和国内多家网站、新浪博客、新浪播客、搜狐通行证、网易新闻、网易播客、金山逍遥网、金山爱词霸、校内...
### Nginx负载均衡配置 在Nginx中,通过`upstream`指令定义负载均衡服务器池,例如: ```nginx upstream bbs_server_pool { server 192.168.1.15:80 weight=1 max_fails=2 fail_timeout=30s; server 192.168....
在金山逍遥网的实际应用案例中,Nginx被用作七层负载均衡器,负责每个机房的Web服务。配置示例中,`upstream`指令定义了一组后端服务器池,通过`proxy_pass`指令将请求转发到这个池中。同时,`proxy_set_header`设置...
在金山逍遥网的实际应用中,Nginx被用来实现七层负载均衡,确保高访问量时的服务稳定。配置示例中,`upstream`指令定义了一个服务器池,包含多台后端服务器,并通过`proxy_pass`指令将请求转发到该池。同时,`proxy_...
金山逍遥网使用Nginx进行七层负载均衡,确保了高并发访问下的稳定性和效率。通过配置Nginx的upstream模块,创建后端服务器池,并通过proxy_pass指令将请求转发至相应服务器。在负载均衡配置中,还考虑了双机热备或互...
第2部分为进阶篇,重点介绍了Nginx的配置优化方法、Nginx与PHP/Ruby/Python/JSP/Perl/Memcached的结合配置方法、Nginx HTTP反向代理与负载均衡的配置与优化、Nginx模块开发等,最后还分析了新浪的开源软件项目──...