##
# You should look at the following URL's in order to grasp a solid understanding
# of Nginx configuration files in order to fully unleash the power of Nginx.
# http://wiki.nginx.org/Pitfalls
# http://wiki.nginx.org/QuickStart
# http://wiki.nginx.org/Configuration
#
# Generally, you will want to move this file somewhere, and start with a clean
# file but keep this around for reference. Or just disable in sites-enabled.
#
# Please see /usr/share/doc/nginx-doc/examples/ for more detailed examples.
##

# Default server configuration
#
server {
	listen 80;
	listen [::]:80;

	server_name music.ataber.pw;
	return 301 https://$host$request_uri; 
}

server {
	listen 443 ssl;
	listen [::]:443 ssl;

	server_name music.ataber.pw;

        ssl_certificate /etc/letsencrypt/live/ataber.pw/fullchain.pem;                                
        ssl_certificate_key /etc/letsencrypt/live/ataber.pw/privkey.pem;                              
        ssl_trusted_certificate /etc/letsencrypt/live/ataber.pw/chain.pem;                            
        ssl_dhparam /etc/ssl/private/dhparam.pem;
        add_header Strict-Transport-Security "max-age=31536000; includeSubDomains; preload" always;

	location = / {
		return 301 https://$host/airsonic;
	}

        location /airsonic {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
		proxy_set_header X-Real-IP         $remote_addr;
		proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
		proxy_set_header X-Forwarded-Proto https;
		proxy_set_header X-Forwarded-Host  $http_host;
		proxy_set_header Host              $http_host;
		proxy_max_temp_file_size           0;
		proxy_pass                         http://127.0.0.1:5002;
		proxy_redirect                     http:// https://;
        }
}

# Virtual Host configuration for example.com
#
# You can move that to a different file under sites-available/ and symlink that
# to sites-enabled/ to enable it.
#
#server {
#	listen 80;
#	listen [::]:80;
#
#	server_name example.com;
#
#	root /var/www/example.com;
#	index index.html;
#
#	location / {
#		try_files $uri $uri/ =404;
#	}
#}