diff --git a/config/nginx-default.conf b/config/nginx-default.conf index 75a37e2..5793e77 100644 --- a/config/nginx-default.conf +++ b/config/nginx-default.conf @@ -1,23 +1,110 @@ +fastcgi_cache_path /dev/shm levels=1:2 keys_zone=laravel:100m; +fastcgi_cache_key "$scheme$request_method$host$request_uri$query_string"; + +map $http_x_forwarded_proto $fastcgi_param_https_variable { + default ''; + https 'on'; +} + +error_log stderr; + server { - listen 8080; - server_name localhost; + access_log /dev/stdout; + + listen 8080 default_server; + server_name _; + + index index.php index.html; + root /var/www/public; + + #client_max_body_size 20M; + client_max_body_size 4G; + + # Compression + + # Enable Gzip compressed. + gzip on; + + # Enable compression both for HTTP/1.0 and HTTP/1.1. + gzip_http_version 1.1; - root /var/www/html; - index index.php index.html index.htm; + # 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 + image/jpeg + image/png + text/css + text/plain + text/x-component; + # text/html is always compressed by HttpGzipModule location / { - try_files $uri $uri/ =404; + try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { - fastcgi_pass 127.0.0.1:9000; + root /var/www/public; + fastcgi_cache off; + fastcgi_cache_valid 200 204 1m; + fastcgi_ignore_headers Cache-Control; + fastcgi_no_cache $http_authorization $cookie_laravel_session; + fastcgi_cache_lock on; + fastcgi_cache_lock_timeout 10s; + + # Bigger buffer size to handle cache invalidation headers expansion + fastcgi_buffer_size 32k; + fastcgi_buffers 8 16k; + + + add_header X-Proxy-Cache $upstream_cache_status; + + fastcgi_pass localhost:9000; fastcgi_index index.php; - fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param HTTPS $fastcgi_param_https_variable; + fastcgi_read_timeout 900s; include fastcgi_params; } - error_page 500 502 503 504 /50x.html; - location = /50x.html { - root /usr/share/nginx/html; + location ~* \.(jpg|jpeg|png|gif|ico|css|js|eot|ttf|woff|woff2)$ { + expires max; + add_header Cache-Control public; + add_header Access-Control-Allow-Origin *; + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ /\.ht { + deny all; } }