Skip to content

Instantly share code, notes, and snippets.

@haykuro
Last active December 28, 2015 07:59
Show Gist options
  • Save haykuro/7467990 to your computer and use it in GitHub Desktop.
Save haykuro/7467990 to your computer and use it in GitHub Desktop.
# /etc/nginx/sites-available/example.com
server {
listen 80;
server_name www.example.com;
return 301 http://example.com$request_uri;
}
server {
listen 80;
server_name example.com;
access_log /var/log/nginx/example.com/access.log;
error_log /var/log/nginx/example.com/error.log;
rewrite_log on;
root /usr/share/nginx/html/example.com/public;
index index.php;
# Added cache headers for images, quick fix for cloudfront.
location ~* \.(png|jpg|jpeg|gif)$ {
expires 30d;
log_not_found off;
}
# Only 3 hours on CSS/JS to allow me to roll out fixes during
# early weeks.
location ~* \.(js|css|ico)$ {
expires 3h;
log_not_found off;
}
# Heres my redirect, try normal URI and then our Laravel urls.
location / {
try_files $uri $uri/ /index.php?$query_string;
# A bunch of perm page redirects from my old
# site structure for SEO purposes. Not interesting.
# include /etc/nginx/templates/redirects;
}
# Look below for this. I decided it was common to Laravel
# sites so put it in an extra template.
include /etc/nginx/templates/laravel4;
}
# /etc/nginx/templates/laravel4:
# Rewrite for content.
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
location ~* \.php$ {
# Server PHP config.
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
# Typical vars in here, nothing interesting.
include /etc/nginx/fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ /\.ht {
# Hells no, we usin nginx up in this mutha. (deny .htaccess)
deny all;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment