安全高效能网站搭建(四)

Ngnix的负载平衡

1 ngnix的原理介绍,请参看:http://blog.csdn.net/chanya/article/details/7745459

2 ngnix的配置文件的说明,请参看:http://blog.csdn.net/chanya/article/details/7747589

3ngnix+fastcgi,fastcgi介绍:http://blog.csdn.net/chanya/article/details/7747628

  配置文件:

 

#用户 用户组
#user  nobody;
#工作进程,根据硬件调整,一般几核cpu,就配几个。
worker_processes  1;
#错误日志
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid文件位置
pid        logs/nginx.pid;


events {
#工作进程的最大连接数,根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行
    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;

    #fastcgi
    server {
        listen       80;
        server_name  127.0.0.1;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   D:\wnmp\www;
           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;
       }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:8080
        location ~ \.php$ {
            root           D:\wnmp\www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$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;
        }
    }


 

4 利用Ngnix实现负载均衡:

配置文件:

 

#用户 用户组
#user  nobody;
#工作进程,根据硬件调整,一般几核cpu,就配几个。
worker_processes  1;
#错误日志
error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
#pid文件位置
pid        logs/nginx.pid;


events {
#工作进程的最大连接数,根据硬件调整,和前面工作进程配合起来用,尽量大,但是别把cpu跑到100%就行
    worker_connections  1024;
}


http{ 
 upstream myproject {  
#这里指定多个源服务器,ip:端口,80端口的话可写可不写  
  server 127.0.0.1:8080;  
  server 192.168.1.87:8088;  
}  
server {  
          listen localhost:80;  
          location / {  
          proxy_pass http://myproject;  
}  
}  
} 


 wnmp集成环境下载,以及配置源文件下载地址:http://download.csdn.net/detail/chanya/4510780

  

你可能感兴趣的:(工作,server,Access,include,redirect,.htaccess)