Skip to content

Instantly share code, notes, and snippets.

@chargoy
Last active October 17, 2022 21:12
Show Gist options
  • Save chargoy/664e43ce0a99f9313d73c497376cfb5a to your computer and use it in GitHub Desktop.
Save chargoy/664e43ce0a99f9313d73c497376cfb5a to your computer and use it in GitHub Desktop.
laravel forge nginx with gzip & expires
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitio.com/before/*;
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name sitio.com;
root /home/forge/sitio.com/public;
# FORGE SSL (DO NOT REMOVE!)
ssl_certificate /etc/nginx/ssl/sitio.com/xxx/server.crt;
ssl_certificate_key /etc/nginx/ssl/sitio.com/xxx/server.key;
ssl_prefer_server_ciphers on;
ssl_dhparam /etc/nginx/dhparams.pem;
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;
charset utf-8;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitio.com/server/*;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
access_log off;
error_log /var/log/nginx/sitio.com-error.log error;
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
# Expire rules for static content -->>
# cache.appcache, your document html and data
location ~* \.(?:manifest|appcache|html?|xml|json)$ {
expires -1;
# access_log logs/static.log; # I don't usually include a static log
}
# Feed
location ~* \.(?:rss|atom)$ {
expires 1h;
add_header Cache-Control "public";
}
# Media: images, icons, video, audio, HTC
location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc|woff)$ {
expires 1M;
access_log off;
add_header Cache-Control "public";
}
# CSS and Javascript
location ~* \.(?:css|js)$ {
expires 1y;
access_log off;
add_header Cache-Control "public";
}
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_buffers 16 8k;
gzip_http_version 1.1;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript image/svg+xml;
# <<--
}
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/sitio.com/after/*;
@ashrafalzyoud
Copy link

if i can ask u?
why u not using proxy??
and cache ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment