# https://www.nginx.com/resources/wiki/start/topics/recipes/symfony/
# NOTE: This makes any .php file other than app, app_dev and config.php
# downloadable. If you want one to run, add it to the "pass the PHP scripts to
# upstream FCGI" location section below. Be careful adding PHP files with
# sensitive data like passwords inside them.

map $host $symfony_root {
    default /home/gliders/code/gliders-website;
}

server {
    listen 80;
    listen 8080;

    server_name gliders.vm dev.gliders.vm;
    root $symfony_root/web;

    error_log /var/log/nginx/gliders.error.log;
    access_log /var/log/nginx/gliders.access.log;

    # strip app.php/ prefix if it is present
    rewrite ^/app\.php/?(.*)$ /$1 permanent;

    location / {
        index app_dev.php;
        try_files $uri @rewriteapp;
    }

    location /static/logs {
        alias /var/gliders/logs;
    }

    location @rewriteapp {
        rewrite ^(.*)$ /app_dev.php/$1 last;
    }

    # pass the PHP scripts to FastCGI server from upstream phpfcgi
    location ~ ^/(app|app_dev|config)\.php(/|$) {
        fastcgi_pass phpfcgi;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param  SCRIPT_FILENAME $symfony_root/web$fastcgi_script_name;
        fastcgi_param  HTTPS off;
    }
}

# We don't yet have an SSL cert (not like a VM on my own machine needs one...)
# server {
#     listen 443;
# 
#     server_name gliders.vm *.gliders.vm;
#     root /home/gliders/code/gliders-website/web;
# 
#     ssl on;
#     ssl_certificate /etc/ssl/certs/symfony2.crt;
#     ssl_certificate_key /etc/ssl/private/symfony2.key;
# 
#     error_log /var/log/nginx/symfony2.error.log;
#     access_log /var/log/nginx/symfony2.access.log;
# 
#     # strip app.php/ prefix if it is present
#     rewrite ^/app\.php/?(.*)$ /$1 permanent;
# 
#     location / {
#         index app.php;
#         try_files $uri @rewriteapp;
#     }
# 
#     location @rewriteapp {
#         rewrite ^(.*)$ /app.php/$1 last;
#     }
# 
#     # pass the PHP scripts to FastCGI server from upstream phpfcgi
#     location ~ ^/(app|app_dev|config)\.php(/|$) {
#         fastcgi_pass phpfcgi;
#         fastcgi_split_path_info ^(.+\.php)(/.*)$;
#         include fastcgi_params;
#         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
#         fastcgi_param HTTPS on;
#     }
# }