server {
  listen *:8000;
  server_name {{ grains['fqdn'] }};

  root /usr/share/webapps/laradev; #Path of laradev symlink directory - should contain symlinks to public folder for each branch of the project
  index index.php;
  access_log /var/log/nginx/laradev_access.log;
  error_log /var/log/nginx/laradev_error.log;

  location = /favicon.ico {
    log_not_found off;
    access_log off;
    expires max;
  }

  location ~ /\. {
    deny all;
    access_log off;
    log_not_found off;
  }

  location ~ \..*/.*\.php$ {
    return 403;
  }

  if (!-d $request_filename) {
    rewrite ^/(.+)/$ /$1 permanent;
  }

  location / {
    try_files $1 $uri $uri/ /index.php$is_args$args;
  }

  location ~ ^/(.*)/index\.php(.*)$ {
    fastcgi_index index.php;
    include /etc/nginx/fastcgi_params;
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
    fastcgi_param SCRIPT_FILENAME /usr/share/webapps/laradev/$1/index.php;
    fastcgi_param LARADEV_CONFIGDIR /etc/laradev; #Not strictly needed
    fastcgi_param REMOTE_USER $remote_user;
  }
}