# technikum29.de on ngninx.

# This lists multiple attemps to make a fused directory (layover)
# working in nginx. Works also with PHP up to little details,
# therefore neglecting. See issue #8 at github for reasoning:
# https://github.com/technikum29/technikum29-www/issues/8

#server {
# listen 80 -> 
#  server_name mail.svenk.org autodiscover.* autoconfig.*;
#  return 301 https://$host$request_uri;
#}
server {
	server_name technikum29.de
	listen 80;
	listen [::]:80;

        root /home/technikum29/www/technikum29.de/checkout; # sic!
        index index.html index.htm index.php;

	location / {
		autoindex on;

		# at least for testing...
		rewrite ^/(static|checkout)/(.*)$ $2 permanent;

		# allows for clean URLs
		if (-f $request_filename.php) {
			rewrite (.*) $1.php last;
		}

		# works but PHP does not (include not allowed in if)
		# allows merging static and checkout directories
#		if (!-e $request_filename) {
#			root /home/technikum29/www/technikum29.de/static;
			# with the new document root, reset DOCUMENT_ROOT etc.
#			include snippets/fastcgi-php.conf;
#			include fastcgi_params;
#		}

		#error_page 404 /lib/404.php;

		try_files $uri $uri/ @static_files;
 #               try_files /checkout/$uri /checkout/$uri/ /static/$uri /static/$uri/ =404;
        }

	# works *almost*, only thing is that index.php files are not detected!!
        location ~ \.php$ {
#		root /home/technikum29/www/technikum29.de; # sic...
 #               try_files /checkout/$uri /static/$uri  =404;
#	        #include snippets/fastcgi-php.conf;
	        include snippets/fastcgi-php.conf;
#	        # include contents of file without try_files:
#		fastcgi_split_path_info ^(.+?\.php)(/.*)$;
#		# Bypass the fact that try_files resets $fastcgi_path_info
#	        # see: http://trac.nginx.org/nginx/ticket/321
#		set $path_info $fastcgi_path_info;
#		fastcgi_param PATH_INFO $path_info;
#		fastcgi_index index.php;
#		include fastcgi.conf;
		# end of snippets/fastcgi-php.conf

                include fastcgi_params;
                fastcgi_pass unix:/run/php/www-t29-fpm.sock;

		# see https://stackoverflow.com/a/28494798
		fastcgi_param SCRIPT_FILENAME $request_filename;
        }

	location @static_files {
		root /home/technikum29/www/technikum29.de/static;
		try_files $uri $uri/ =404;
	}
}
