user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
	worker_connections 768;
	# multi_accept on;
}



http {

	client_header_buffer_size    64k;
	client_body_buffer_size     64k;
	large_client_header_buffers 8 512k;	
	client_max_body_size 100m;	
	
	log_format custom 'site="$server_name" server="$host" dest_port="$server_port" dest_ip="$server_addr" '
                   'src="$remote_addr" src_ip="$realip_remote_addr" user="$remote_user" '
                   'time_local="$time_local" protocol="$server_protocol" status="$status" '
                   'bytes_out="$body_bytes_sent" bytes_in="$upstream_response_length" '
                   'http_referer="$http_referer" http_user_agent="$http_user_agent" '
                   'nginx_version="$nginx_version" http_x_forwarded_for="$http_x_forwarded_for" '
                   'http_x_header="$http_x_header" uri_query="$query_string" uri_path="$uri" '
                   'http_method="$request_method" response_time="$upstream_response_time" '
                   'cookie="$http_cookie" request_time="$request_time" ';
				   
	##
	# Basic Settings
	##

	sendfile on;
	tcp_nopush on;
	tcp_nodelay on;
	keepalive_timeout 65;
	types_hash_max_size 2048;
	# server_tokens off;

	# server_names_hash_bucket_size 64;
	# server_name_in_redirect off;

	include /etc/nginx/mime.types;
	default_type application/octet-stream;

	##
	# SSL Settings
	##

	ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
	ssl_prefer_server_ciphers on;

	##
	# Logging Settings
	##

	#access_log /var/log/nginx/access.log custom;
	access_log off;
	error_log /var/log/nginx/error.log;

	##
	# Gzip Settings
	##

	gzip on;

	# gzip_vary on;
	# gzip_proxied any;
	# gzip_comp_level 6;
	# gzip_buffers 16 8k;
	# gzip_http_version 1.1;
	# gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

	##
	# Virtual Host Configs
	##

	include /etc/nginx/conf.d/*.conf;
	include /etc/nginx/sites-enabled/*;
	map_hash_max_size 262144;
	map_hash_bucket_size 262144;
	
	#nolocale
	map $http_host$request_uri $dest_nolocale_301 {
		hostnames;
		include /etc/nginx/sites-available/nolocale-301.map;
	}	
	
	map $http_host$uri $dest_nolocale_no_qs_301 {
		hostnames;
		include /etc/nginx/sites-available/nolocale-no-qs-301.map;		
	}

	map $http_host$request_uri $dest_nolocale_302 {
		hostnames;
		include /etc/nginx/sites-available/nolocale-302.map;
	}	
	
	map $http_host$uri $dest_nolocale_no_qs_302 {
		hostnames;
		include /etc/nginx/sites-available/nolocale-no-qs-302.map;		
	}		
	
	#en-us
	map $http_host$request_uri $dest_en_us_301 {
		hostnames;
		include /etc/nginx/sites-available/en-us-301.map;
	}	

	map $http_host$uri $dest_en_us_no_qs_301 {
		hostnames;
		include /etc/nginx/sites-available/en-us-no-qs-301.map;		
	}
	
	map $http_host$request_uri $dest_en_us_302 {
		hostnames;
		include /etc/nginx/sites-available/en-us-302.map;
	}	

	map $http_host$uri $dest_en_us_no_qs_302 {
		hostnames;
		include /etc/nginx/sites-available/en-us-no-qs-302.map;		
	}	
	
	#en-ca
	map $http_host$request_uri $dest_en_ca_301 {
		hostnames;
		include /etc/nginx/sites-available/en-ca-301.map;
	}	

	map $http_host$uri $dest_en_ca_no_qs_301 {
		hostnames;
		include /etc/nginx/sites-available/en-ca-no-qs-301.map;		
	}
	
	map $http_host$request_uri $dest_en_ca_302 {
		hostnames;
		include /etc/nginx/sites-available/en-ca-302.map;
	}	

	map $http_host$uri $dest_en_ca_no_qs_302 {
		hostnames;
		include /etc/nginx/sites-available/en-ca-no-qs-302.map;		
	}		
	
	#fr-ca
	map $http_host$request_uri $dest_fr_ca_301 {
		hostnames;
		include /etc/nginx/sites-available/fr-ca-301.map;
	}	

	map $http_host$uri $dest_fr_ca_no_qs_301 {
		hostnames;
		include /etc/nginx/sites-available/fr-ca-no-qs-301.map;		
	}
	
	map $http_host$request_uri $dest_fr_ca_302 {
		hostnames;
		include /etc/nginx/sites-available/fr-ca-302.map;
	}	

	map $http_host$uri $dest_fr_ca_no_qs_302 {
		hostnames;
		include /etc/nginx/sites-available/fr-ca-no-qs-302.map;		
	}				
	
	server {
		listen 80;
		server_name www2.indianmotorcycle.com;
		#access_log /var/log/nginx/access.log custom;	

		
		location ~* ^/en-us/ {
			#access_log /var/log/nginx/access.log custom;
			if ($dest_en_us_301) 
			{ 
				return 301 https://$dest_en_us_301; 
			}	
			if ($dest_en_us_no_qs_301) 
			{ 
				return 301 https://$dest_en_us_no_qs_301; 
			}	
			if ($dest_en_us_302) 
			{ 
				return 302 https://$dest_en_us_302; 
			}	
			if ($dest_en_us_no_qs_302) 
			{ 
				return 302 https://$dest_en_us_no_qs_302; 
			}		
			return 301 https://www.indianmotorcycle.com/en-us/;			
		} 		

		location ~* ^/en-ca/ {
			#access_log /var/log/nginx/access.log custom;
			if ($dest_en_ca_301) 
			{ 
				return 301 https://$dest_en_ca_301; 
			}	
			if ($dest_en_ca_no_qs_301) 
			{ 
				return 301 https://$dest_en_ca_no_qs_301; 
			}	
			if ($dest_en_ca_302) 
			{ 
				return 302 https://$dest_en_ca_302; 
			}	
			if ($dest_en_ca_no_qs_302) 
			{ 
				return 302 https://$dest_en_ca_no_qs_302; 
			}		
			return 301 https://www.indianmotorcycle.com/en-us/;				
		} 	

		location ~* ^/fr-ca/ {
			#access_log /var/log/nginx/access.log custom;
			if ($dest_fr_ca_301) 
			{ 
				return 301 https://$dest_fr_ca_301; 
			}	
			if ($dest_fr_ca_no_qs_301) 
			{ 
				return 301 https://$dest_fr_ca_no_qs_301; 
			}	
			if ($dest_fr_ca_302) 
			{ 
				return 302 https://$dest_fr_ca_302; 
			}	
			if ($dest_fr_ca_no_qs_302) 
			{ 
				return 302 https://$dest_fr_ca_no_qs_302; 
			}
			return 301 https://www.indianmotorcycle.com/en-us/;				
		} 			
				
		location / {
			#access_log /var/log/nginx/access.log custom;
			if ($dest_nolocale_301) 
			{ 
				return 301 https://$dest_nolocale_301; 
			}		
			if ($dest_nolocale_no_qs_301) 
			{ 
				return 301 https://$dest_nolocale_no_qs_301; 
			}			
			if ($dest_nolocale_302) 
			{ 
				return 302 https://$dest_nolocale_302; 
			}		
			if ($dest_nolocale_no_qs_302) 
			{ 
				return 302 https://$dest_nolocale_no_qs_302; 
			}					
			return 301 https://www.indianmotorcycle.com/en-us/;	
		}
	  }
}


