nginx.conf负载均衡配置

负载均衡配置(nginx.conf文件):

#user  nobody;
worker_processes  2;  


#错误日志存放路径  
#error_log  logs/error.log;  
#error_log  logs/error.log  notice;  
error_log  logs/error.log  info; 


#指定pid存放文件  
pid        logs/nginx.pid; 




events {  
    #使用网络IO模型linux建议epoll,FreeBSD建议采用kqueue,window下不指定。  
    #use epoll;  
      
    #允许最大连接数  
    worker_connections  2048;  
} 




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  off;  
    access_log  logs/access.log;  
  
    client_header_timeout  3m;  
    client_body_timeout    3m;  
    send_timeout           3m;  
   
    client_header_buffer_size    1k;  
    large_client_header_buffers  4 4k;  
  
    sendfile        on;  
    tcp_nopush      on;  
    tcp_nodelay     on;  
  
    #keepalive_timeout  75 20;  
  
    #include    gzip.conf;  
	
	#负载均衡配置,#server localhost:8082; 
    upstream localhost {  
      #同一机器在多网情况下,路由切换,ip可能不同  
      #ip_hash;
      server 192.168.3.63:8080; 
	  server 192.168.3.64:8081;
      server 192.168.3.65:8082;
     }
	 
    #代理web服务
    server {  
           listen       8088;  
           server_name  localhost;   
		    charset utf-8;  
			location / {
				root   html;
				index  index.html index.htm index.jsp;
				proxy_pass http://localhost/;
				proxy_set_header  X-Real-IP  $remote_addr;  
				client_max_body_size  100m;
			}
			location ~ ^/(WEB-INF)/ {   
				deny all;   
			}   
			error_page   500 502 503 504  /50x.html;  
			location = /50x.html {  
				root   html;  
			}  
    	}    	
	

        location / {
            root   html;
            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: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;
        #}
    }
}  


nginx命令:

nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

关闭nginx:
nginx -s stop  :快速停止nginx
nginx -s quit  :完整有序的停止nginx

启动nginx:
nginx -c D:\Java\nginx\nginx-1.6.3\conf\nginx.conf

配置错误:
错误1:没有相应的文件夹(D:/resourecefile/images)
nginx.conf负载均衡配置_第1张图片
解决方法:添加相应的文件夹(D:/resourecefile/images)

错误2:nginx没有启动

解决方法:执行nginx.exe或命令提示符下执行 nginx -c D:\Java\nginx\nginx-1.6.3\conf\nginx.conf再执行nginx -s reload

你可能感兴趣的:(配置文件)