Skip to content

Instantly share code, notes, and snippets.

@frengky
Last active September 9, 2018 17:35
Show Gist options
  • Save frengky/98ed5d22a0d4c819e2115e75591c1730 to your computer and use it in GitHub Desktop.
Save frengky/98ed5d22a0d4c819e2115e75591c1730 to your computer and use it in GitHub Desktop.
Nginx configuration for Laravel
# Compression
# Enable Gzip compressed.
gzip on;
# Enable compression both for HTTP/1.0 and HTTP/1.1.
gzip_http_version 1.1;
# Compression level (1-9). 5 is a perfect compromise between size and cpu usage, offering about 75% reduction for most ascii
# files (almost identical to level 9).
gzip_comp_level 5;
# Don't compress anything that's already small and unlikely to shrink much if at all (the default is 20 bytes, which is bad as
# that usually leads to larger files after gzipping).
gzip_min_length 256;
# Compress data even for clients that are connecting to us via proxies, identified by the "Via" header (required for
# CloudFront).
gzip_proxied any;
# Tell proxies to cache both the gzipped and regular version of a resource whenever the client's Accept-Encoding capabilities
# header varies; Avoids the issue where a non-gzip capable client (which is extremely rare today) would display gibberish if
# their proxy gave them the gzipped version.
gzip_vary on;
# Compress all output labeled with one of the following MIME-types.
gzip_types
application/atom+xml
application/javascript
application/json
application/rss+xml
application/vnd.ms-fontobject
application/x-font-ttf
application/x-web-app-manifest+json
application/xhtml+xml
application/xml
font/opentype
image/svg+xml
image/x-icon
text/css
text/javascript
text/plain
text/x-component;
# text/html is always compressed by HttpGzipModule
server {
listen 80;
server_name frengky.local;
return 301 $scheme://www.frengky.local$request_uri;
}
server {
listen 80;
# server_name www.frengky.local;
# root /autofs/sites/localhost/public;
server_name ~^(.*)\.frengky\.local$;
set $subdomain $1;
set $baseroot /autofs/sites;
set $docroot "";
if (-d "${baseroot}/${subdomain}/public") {
set $docroot "/public";
}
root "${baseroot}/${subdomain}${docroot}";
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.html index.htm index.php;
autoindex on;
charset utf-8;
client_max_body_size 64M;
include gzip_params;
location / {
##
# auth_basic "Restricted Content";
# auth_basic_user_file /etc/nginx/.htpasswd;
##
## user:`openssl passwd -apr1`
try_files $uri $uri/ /index.php?$query_string;
}
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm/frengky.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
## If your server_name are using regex
# fastcgi_param SERVER_NAME $http_host;
}
location ~ /storage/(.*)$ {
alias /autofs/sites/localhost/storage/app/public/$1;
# add_header Cache-Control "public";
# expires max;
expires -1;
access_log off;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
## Images
location ~* \.(?:jpg|jpeg|gif|png|ico|svg)$ {
sendfile on;
# add_header Cache-Control "public";
# expires max;
expires -1;
access_log off;
}
## Javascripts and CSS
location ~* \.(?:css|js)$ {
# add_header Cache-Control "public";
# expires max;
expires -1;
access_log off;
}
location ~ /\.ht { access_log off; log_not_found off; deny all; }
location ~ /\.(?!well-known).* { deny all; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment