您的位置:首页 > 运维架构 > Nginx

nginx负载 发向代理配置文件参考

2015-11-20 13:17 676 查看
来自server+iis linux可做参考 :

#user  nobody;
worker_processes  8;

#worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000;

worker_rlimit_nofile 102400;
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {
use epoll;
worker_connections  102400;
}

http {
include       mime.types;
default_type  application/octet-stream;
#proxy_cache_path d:\imgdata\cache levels=1:2 keys_zone=imgcache:100m inactive=1d max_size=10g;
#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;
client_header_buffer_size 8k;
client_max_body_size 24m;

gzip  on;

upstream www.yunxindai.com{

#server ip1:8080 weight=1 max_fails=2 fail_timeout=30s;
server ip2:80 weight=3 max_fails=2 fail_timeout=30s;
#server ip3:80 weight=3 max_fails=2 fail_timeout=30s;
server ip4:80 weight=3 max_fails=2 fail_timeout=30s;
server ip5:80 backup;
#server ip6:80 weight=3 max_fails=2 fail_timeout=30s;
ip_hash;
}

#domain tiaozhuan
server {
listen       80;
server_name  www.xx.net;
server_name  www.xx.cn;
server_name  xx.com;
#server_name  www.xx.com.cn;
rewrite
^/(.*) http://www.yunxindai.com/$1 permanent;
}

server {
listen       80;
server_name  ip1;
server_name  www.xx.com;
#server_name  www.xx.cn;
server_name  www.xx.com.cn;
#server_name  www.xx.net;

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://www.yunxindai.com; #proxy_redirect default;
proxy_redirect off;
proxy_set_header x-real-ip $remote_addr;
proxy_set_header remote-host $remote_addr;
proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;
}

#error_page  404              /404.html;

# redirect server error pages to the static page /50x.html
#
error_page   404 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;
#    }
#}

}


本人配置如下:

user  nginx;
worker_processes  8;
worker_rlimit_nofile 51200;

error_log  /var/log/nginx/error.log warn;
pid        /var/run/nginx.pid;

events {
use epoll;
worker_connections  51200;
}

http {
include       /etc/nginx/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  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

#gzip  on;

include /etc/nginx/conf.d/*.conf;

#设定负载均衡的服务器列表
upstream myServer {
#weigth参数表示权值,权值越高被分配到的几率越大
#本机上的apache开8080端口
server ip1:8080 weight=4 max_fails=2 fail_timeout=25s;
server ip2:80 weight=6 max_fails=2 fail_timeout=25s;
ip_hash;
}

server {
listen 80;
server_name  域名;  #可加多个域名
server_name  ip1;
location / {
proxy_pass http://myServer; proxy_redirect  off;
proxy_set_header X-Real-IP $remote_addr;  #应用服务器上显示正式客户端ip

}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: