From 7f93f5fbd02fc5b763f0d0918156bd88ab019a2b Mon Sep 17 00:00:00 2001 From: Hardware Date: Sat, 29 Oct 2016 19:36:42 +0200 Subject: [PATCH] feat(): add custom error pages support --- README.md | 10 +++++++++ nginx.conf | 65 ++++++++++++++++++++++++++++++++++++++++-------------- run.sh | 5 +++++ 3 files changed, 63 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 72dcb68..8d3a6ab 100644 --- a/README.md +++ b/README.md @@ -134,6 +134,16 @@ docker exec -ti flarum extension remove some/extension docker exec -ti flarum extension list ``` +### Custom error pages + +To use custom error pages, add your .html files in `/mnt/docker/flarum/assets/errors` folder : + +``` +mkdir -p /mnt/docker/flarum/assets/errors +touch 403.html 404.html 500.html 503.html +chown -R 991:991 /mnt/docker/flarum +``` + ### Screenshot #### Installation diff --git a/nginx.conf b/nginx.conf index 5cc6e28..b1cebec 100644 --- a/nginx.conf +++ b/nginx.conf @@ -58,46 +58,77 @@ http { root /flarum/app; index index.php; charset utf-8; + client_max_body_size 50M; + fastcgi_buffers 64 4K; - location / { - try_files $uri $uri/ /index.php?$query_string; - } + error_page 403 /403.html; + error_page 404 /404.html; + error_page 500 /500.html; + error_page 503 /503.html; - location /api { - try_files $uri $uri/ /api.php?$query_string; - } + location = /403.html { root /flarum/app/vendor/flarum/core/error; } + location = /404.html { root /flarum/app/vendor/flarum/core/error; } + location = /500.html { root /flarum/app/vendor/flarum/core/error; } + location = /503.html { root /flarum/app/vendor/flarum/core/error; } - location /admin { - try_files $uri $uri/ /admin.php?$query_string; - } + location / { try_files $uri $uri/ /index.php?$query_string; } + location /api { try_files $uri $uri/ /api.php?$query_string; } + location /admin { try_files $uri $uri/ /admin.php?$query_string; } - location /flarum { + # Access path list + # -------------------------------------- + location ~ /\. { deny all; return 404; } - location ~ /\.ht { - deny all; + location ~* ^/(Procfile|storage|Vagrantfile|config\.php|LICENSE|vendor|flarum|scripts) { + deny all; + return 404; } - location ~* \.html$ { + location ~* composer(.*?) { + deny all; + return 404; + } + + location ~* (.*?)\.md { + deny all; + return 404; + } + + # Assets cache control + # -------------------------------------- + location ~* \.(?:html|xml|json)$ { expires -1; } - location ~* \.(css|js|gif|jpe?g|png)$ { - expires 1M; + location ~* \.(?:css|js)$ { + expires 7d; add_header Pragma public; add_header Cache-Control "public, must-revalidate, proxy-revalidate"; } + location ~* \.(?:gif|jpe?g|png|ico|otf|eot|svg|ttf|woff|woff2)$ { + expires 30d; + add_header Pragma public; + add_header Cache-Control "public, must-revalidate, proxy-revalidate"; + } + + # PHP Backend + # -------------------------------------- location ~* \.php$ { - fastcgi_split_path_info ^(.+.php)(/.+)$; - fastcgi_pass unix:/tmp/php-fpm.sock; + try_files $uri =404; include fastcgi_params; + fastcgi_split_path_info ^(.+\.php)(/.*)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param HTTP_PROXY ""; fastcgi_index index.php; + fastcgi_pass unix:/tmp/php-fpm.sock; + fastcgi_intercept_errors on; + fastcgi_request_buffering off; } } diff --git a/run.sh b/run.sh index 3bb7c36..40e7462 100644 --- a/run.sh +++ b/run.sh @@ -28,6 +28,11 @@ chown -R $UID:$GID /flarum /etc/nginx /etc/php7 /var/log /var/lib/nginx /tmp /et cd /flarum/app +if [ -d 'assets/errors' ]; then + rm -rf vendor/flarum/core/error/* + ln -s /flarum/app/assets/errors/* vendor/flarum/core/error +fi + # if no installation was performed before if [ -e 'assets/rev-manifest.json' ]; then