# 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 files with
# sensitive data like passwords inside them.

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

map $host $symfony_root_dev {
   default /var/gliders/www_dev;
}

server {
    listen 80;

    server_name gliders.vm;
    root $symfony_root/web;

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

    # Enable compression. Very helpful when we're getting stuff like
    # large amounts of vehicle tracks in JSON form!
    gzip on;
    gzip_types text/plain application/xml text/html text/css application/json application/x-javascript text/xml text/javascript;

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

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

    location ~ ^/(images|fonts|css|js) {
        access_log off;
        error_log off;
        try_files $uri =404;
        expires 1y;
        add_header Cache-Control "public";
    }

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

    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;
        include fastcgi_params;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param  SCRIPT_FILENAME $symfony_root/web$fastcgi_script_name;
        fastcgi_param  HTTPS off;
    }
}

server {
    listen 80;

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

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

    # Enable compression. Very helpful when we're getting stuff like
    # large amounts of vehicle tracks in JSON form!
    gzip on;
    gzip_types text/plain application/xml text/html text/css application/json application/x-javascript text/xml text/javascript;

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

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

    location ~ ^/(images|fonts|css|js) {
        access_log off;
        error_log off;
        try_files $uri =404;
        expires 1y;
        add_header Cache-Control "public";
    }

    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_dev/web$fastcgi_script_name;
        fastcgi_param  HTTPS off;
    }
}