worker_processes  auto;

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

events {
    worker_connections 1024;
}

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"';

    sendfile on;
    keepalive_timeout 65;

	map $http_upgrade $connection_upgrade {
		default upgrade;
		'' close;
	}

	upstream rdio-scanner {
		server 127.0.0.1:3000;
	}

	server {
		listen 80 default_server;
		listen [::]:80 default_server;

		# listen 443 ssl default_server;
		# listen [::]:443 ssl default_server;
		#
		# ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem;
		# ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key;

		root /var/www/html;

		index index.html index.htm;

		server_name _;

		location / {
			try_files $uri $uri/ =404;
		}

		location /rdio-scanner/ {
			rewrite ^/rdio-scanner/(.*)$ /$1 break;
			proxy_pass http://rdio-scanner;
		}

		proxy_http_version 1.1;
		proxy_set_header Connection $connection_upgrade;
		proxy_set_header Host $host;
		proxy_set_header Upgrade $http_upgrade;
		proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
	}
}
