Last active
November 3, 2023 07:20
-
-
Save haubar/f0055ec4b32436ba9a8334069bbb500f to your computer and use it in GitHub Desktop.
ngix auto thumbnail and config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80 default_server; | |
server_name localhost; | |
if ($host != "localhost") { | |
#return 404; | |
} | |
root /var/www/html/production/public; | |
index index.php; | |
access_log /var/log/nginx/production-access.log; | |
error_log /var/log/nginx/production-error.log error; | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
add_header Cache-Control no-cache; | |
add_header Cache-Control private; | |
proxy_set_header Host $http_host; | |
} | |
#location ~* /uploads/(.+)$ { | |
location ~* /uploads/(.+)\.(jpg|jpeg|gif|png|svg)$ { | |
access_log off; | |
alias /var/www/html/production/public/uploads/$1.$2; | |
set $width -; | |
if ($arg_w != ""){ | |
set $width $arg_w; | |
} | |
set $height -; | |
if ($arg_h != ""){ | |
set $height $arg_h; | |
} | |
image_filter resize $width $height; | |
image_filter_buffer 6M; | |
image_filter_interlace on; | |
} | |
location ~* /thumbnail/(\d+)x(\d+)/(.+)$ { | |
access_log off; | |
if ( -e $document_root/uploads/$3 ) { | |
rewrite /thumbnail/(\d+)x(\d+)\/(.+)$ /uploads/$3?w=$1&h=$2 last; | |
} | |
#return 404; | |
} | |
location ~* /thumbnail/(\d+)/(.+)$ { | |
access_log off; | |
if ( -e $document_root/uploads/$2 ) { | |
rewrite /thumbnail/(\d+)/(.+)$ /uploads/$2?w=$1 last; | |
} | |
#return 404; | |
} | |
location ~* \.(css|js|jpg|jpeg|gif|png|ico|svg|otf|ttf|eot|woff|woff2)$ { | |
access_log off; | |
expires 1d; | |
add_header Cache-Control no-cache; | |
##add_header Cache-Control "public, no-transform"; | |
} | |
location ~ \.php$ { | |
try_files $uri =404; | |
fastcgi_pass 127.0.0.1:9000; | |
fastcgi_index index.php; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
fastcgi_read_timeout 1200; | |
include fastcgi_params; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment