Skip to content

Instantly share code, notes, and snippets.

@benbowler
Forked from electblake/nginx.conf.erb
Created July 11, 2014 14:15
Show Gist options
  • Save benbowler/0875cbfa763a1dd9df43 to your computer and use it in GitHub Desktop.
Save benbowler/0875cbfa763a1dd9df43 to your computer and use it in GitHub Desktop.
## Customized for Laravel 4
# setting worker_processes to CPU core count
worker_processes 1;
daemon off;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
server_tokens off;
keepalive_timeout 65;
gzip on;
access_log off;
error_log logs/error.log;
proxy_max_temp_file_size 0;
#fastcgi_max_temp_file_size 0;
limit_conn_zone $binary_remote_addr zone=phplimit:1m; # define a limit bucket for PHP-FPM
# don't use server listen port in redirects.
port_in_redirect off;
# set $https only when SSL is actually used.
map $http_x_forwarded_proto $my_https {
default off;
https on;
}
upstream php_fpm {
server unix:/tmp/php-fpm.socket;
}
root /app/public/;
index index.php index.html index.htm;
server {
listen <%= ENV['PORT'] %>;
server_name _;
# Some basic cache-control for static files to be sent to the browser
location ~* \.(?:ico|css|js|gif|jpeg|jpg|png)$ {
expires max;
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
}
# Deny hidden files (.htaccess, .htpasswd, .DS_Store).
location ~ /\. {
deny all;
access_log off;
log_not_found off;
}
# Deny /favicon.ico
location = /favicon.ico {
access_log off;
log_not_found off;
}
# Deny /robots.txt
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
# Status. /status.html uses /status
location ~ ^/(status|ping)$ {
include fastcgi_params;
fastcgi_param HTTPS $my_https if_not_empty;
fastcgi_pass php_fpm;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location /server-status {
stub_status on;
access_log off;
}
#location / {
# # wordpress fancy rewrites
# if (-f $request_filename) {
# break;
# }
# if (-d $request_filename) {
# break;
# }
# rewrite ^(.+)$ /index.php?q=$1 last;
# # Add trailing slash to */wp-admin requests.
# rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# # redirect to feedburner.
# # if ($http_user_agent !~ FeedBurner) {
# # rewrite ^/feed/?$ http://feeds.feedburner.com/feedburner-feed-id last;
# # }
#}
include /app/conf/nginx.d/*.conf;
# serve static files directly
location ~* \.(jpg|jpeg|gif|css|png|js|ico|html)$ {
access_log off;
expires max;
}
# removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename)
{
rewrite ^/(.+)/$ /$1 permanent;
}
# enforce NO www
if ($host ~* ^www\.(.*))
{
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename)
{
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# catch all
error_page 404 /index.php;
location ~ .*\.php$ {
try_files $uri =404;
limit_conn phplimit 5; # limit to 5 concurrent users to PHP per IP.
include fastcgi_params;
fastcgi_param HTTPS $my_https if_not_empty;
fastcgi_pass php_fpm;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment