
user  root;
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;
}


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;
	client_max_body_size 300m;
    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

	#负载均衡
	upstream gateway{
		server 127.0.0.1:7140 weight=1;
		server 192.168.0.1:7140 weight=1;
	}

	server{
		listen       80;
        server_name  www.lxnn.top;
		gzip on;
		gzip_min_length 1k;
		gzip_buffers 4 16k;
		gzip_http_version 1.1;
		gzip_comp_level 9;
		gzip_types text/plain application/javascript application/x-javascript text/css application/xml image/jpg image/gif image/png image/jpeg mp4 media;
		gzip_vary on;
		proxy_send_timeout 1800s; 
		proxy_read_timeout 1800s;
		
		location /{
			root /usr/local/nginx/html/tools/;
			index index.html;
		}

		location /v3docs/{
			alias /usr/local/nginx/html/v3docs/;
			index off;
		}
		
	}
	
	server {
		listen       443 ssl;
		server_name  www.concare.cn;
		
		ssl_certificate /usr/local/nginx/conf/ssl/www.lxnn.top.pem;   #将domain name.pem替换成您证书的文件名。
		ssl_certificate_key /usr/local/nginx/conf/ssl/www.lxnn.top.key;   #将domain name.key替换成您证书的密钥文件名。
		ssl_session_timeout 5m;
		ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;  #使用此加密套件。
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;   #使用该协议进行配置。
		ssl_prefer_server_ciphers on;

		#开启压缩
		gzip on;
		gzip_min_length 1k;
		gzip_buffers 4 16k;
		gzip_http_version 1.1;
		gzip_comp_level 2;
		gzip_types text/plain application/javascript application/x-javascript text/css application/xml image/jpg image/gif image/png image/jpeg application/json;
		gzip_vary on;
		
		proxy_send_timeout 1800s; 
		proxy_read_timeout 1800s;
		proxy_set_header x-forwarded-for  $remote_addr;
		#access_log /usr/share/nginx/logs/ehr/access-$logdate.log pro;
		#解决跨域问题
	    add_header Access-Control-Allow-Methods *;
		add_header Access-Control-Max-Age 3600;
		add_header Access-Control-Allow-Credentials true;
		add_header Access-Control-Allow-Origin $http_origin;
		add_header Access-Control-Allow-Headers
		$http_access_control_request_headers;

		if ($request_method = OPTIONS){
				return 200;
		}
		
		location /{
			root html;
			index index.html;
		}

		location /demo/{
			root /usr/local/nginx/html/;
			index index.html;
		}
		
		location /views/{
			alias /usr/local/nginx/html/;
			autoindex off;
		}
		
		#反向代理，负载均衡例子
		location ^~ /concare/{
			proxy_pass   http://gateway/;
			proxy_next_upstream error timeout http_404; #off表示不重试
			proxy_next_upstream_timeout 6s;
			proxy_next_upstream_tries 3;
		}
    }

}
