Skip to content

Instantly share code, notes, and snippets.

@ddmills
Created February 21, 2016 15:29
Show Gist options
  • Save ddmills/e7620f771aa6111f52e4 to your computer and use it in GitHub Desktop.
Save ddmills/e7620f771aa6111f52e4 to your computer and use it in GitHub Desktop.
nginx web server configuration for laravel. Being used on an AWS EC2 instance with ubuntu 14.04. Note that Rocketeer is being used for deployment/CI.
server {
# Port that the web server will listen on.
listen 80;
# Host that will serve this project.
server_name my-project.local;
access_log /var/www/my-project/log/access.log;
error_log /var/www/my-project/log/error.log;
rewrite_log on;
# The location of our projects public directory.
root /var/www/my-project/current/public;
# Point index to the Laravel front controller.
index index.php;
location / {
# URLs to attempt, including pretty ones.
try_files $uri $uri/ /index.php?$query_string;
}
# Remove trailing slash to please routing system.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# PHP FPM configuration.
location ~* \.php$ {
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
include /etc/nginx/fastcgi_params;
# When you are using symlinks to link the document root to the
# current version of your application, you should pass the real
# application path instead of the path to the symlink to PHP
# FPM.
# Otherwise, PHP's OPcache may not properly detect changes to
# your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
# for more information).
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root;
}
# We don't need .ht files with nginx.
location ~ /\.ht {
deny all;
}
# Set header expirations on per-project basis
location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
expires 365d;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment