Advertisement
hfelix

Nginx vhost example

Jan 25th, 2022 (edited)
557
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fastcgi_cache_path /tmp/nginx levels=1:2 keys_zone=my_zone:10m inactive=60m;
  2. fastcgi_cache_key "$scheme$request_method$host$request_uri";
  3.  
  4. upstream remote_fpm {
  5.     server php-fpm:9000;
  6.     # least_conn = round-robin
  7. }
  8.  
  9. server {
  10.     listen 80;
  11.     listen [::]:80;
  12.  
  13.     charset utf-8;
  14.  
  15.     server_name 127.0.0.1 localhost felix-windows;
  16.     root /var/www/public;
  17.  
  18.     index index.html index.htm index.php;
  19.  
  20.     error_log  /var/log/nginx/error.log;
  21.     access_log /var/log/nginx/access.log;
  22.  
  23.     location ~ \.php$ {
  24.         try_files $uri =404;
  25.         fastcgi_split_path_info ^(.+\.php)(/.+)$;
  26.         fastcgi_pass remote_fpm;
  27.         fastcgi_index index.php;
  28.         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  29.         fastcgi_param PATH_INFO $fastcgi_path_info;
  30.         fastcgi_intercept_errors off;
  31.         fastcgi_buffer_size 16k;
  32.         fastcgi_buffers 4 16k;
  33.         fastcgi_connect_timeout 600;
  34.         fastcgi_send_timeout 600;
  35.         fastcgi_read_timeout 600;
  36.         include fastcgi_params;
  37.  
  38.         # fastcgi_cache my_zone;
  39.         fastcgi_cache_valid 200 60m; # Only cache 200 responses, cache for 60 minutes
  40.         fastcgi_cache_methods GET HEAD; # Only GET and HEAD methods apply
  41.         add_header X-Fastcgi-Cache $upstream_cache_status;
  42.         fastcgi_cache_bypass $http_cache_control;  # Don't pull from cache based on $no_cache
  43.         fastcgi_no_cache $http_cache_control; # Don't save to cache based on $no_cache
  44.     }
  45.    
  46.     location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
  47.         expires max;
  48.         log_not_found off;
  49.     }
  50.  
  51.     location = /favicon.ico {
  52.         access_log off;
  53.         log_not_found off;
  54.     }
  55.  
  56.     location = /robots.txt  {
  57.         access_log off;
  58.         log_not_found off;
  59.     }
  60.  
  61.     location ~ /\.(?!well-known).* {
  62.         deny all;
  63.     }
  64.  
  65.     location / {
  66.         try_files $uri $uri/ /index.php?$query_string;
  67.         add_header X-Proxy-Cache $upstream_cache_status;
  68.         gzip_static on;
  69.     }
  70. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement