diff --git a/install/01-nginx-default-root.sh b/install/01-nginx-default-root.sh index ee3c783..f6afa28 100755 --- a/install/01-nginx-default-root.sh +++ b/install/01-nginx-default-root.sh @@ -44,7 +44,7 @@ server { # Check for banned IPs if (\$is_banned) { - return 403 "IP banned for bad behavior"; + return 403; } location / { diff --git a/install/error-pages.sh b/install/error-pages.sh new file mode 100644 index 0000000..9bf4191 --- /dev/null +++ b/install/error-pages.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +# Check if script is run as root +if [ "$EUID" -ne 0 ]; then + echo "Please run as root or with sudo" + exit 1 +fi + +# Get the directory where this script is located +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +# Define source and destination directories using absolute path +SRC_DIR="$SCRIPT_DIR/error-pages" +DEST_DIR="/var/www/error-pages" + +# Check if source directory exists +if [ ! -d "$SRC_DIR" ]; then + echo "Source directory '$SRC_DIR' not found" + exit 1 +fi + +# Create destination directory if it doesn't exist +mkdir -p "$DEST_DIR" + +# Copy all .conf files +echo "Copying configuration files..." +cp -v "$SRC_DIR"/*.conf "$DEST_DIR/" + +# Set proper permissions +echo "Setting permissions..." + +# Set directory ownership and permissions +sudo chown root:root /var/www/error-pages +sudo chmod 755 /var/www/error-pages + +# Set file ownership and permissions +sudo chown root:root /var/www/error-pages/* +sudo chmod 644 /var/www/error-pages/* diff --git a/install/error-pages/403.html b/install/error-pages/403.html new file mode 100644 index 0000000..a046924 --- /dev/null +++ b/install/error-pages/403.html @@ -0,0 +1,69 @@ + + + + + + + 403 Forbidden + + + + +
+

403 Access Forbidden

+

Sorry, you don't have permission to access this resource.

+
+

If you believe this is a mistake:

+ +
+
+ + + \ No newline at end of file diff --git a/install/error-pages/404.html b/install/error-pages/404.html new file mode 100644 index 0000000..e703ee3 --- /dev/null +++ b/install/error-pages/404.html @@ -0,0 +1,69 @@ + + + + + + + 404 Not Found + + + + +
+

404 Page Not Found

+

Sorry, we couldn't find the page you're looking for.

+
+

You might want to:

+ +
+
+ + + \ No newline at end of file diff --git a/install/error-pages/503.html b/install/error-pages/503.html new file mode 100644 index 0000000..8dd2b8d --- /dev/null +++ b/install/error-pages/503.html @@ -0,0 +1,80 @@ + + + + + + + 503 Service Unavailable + + + + + +
+

503 Temporarily Unavailable

+

The site is currently undergoing maintenance and will be back shortly.

+
+

What you should know:

+ +
+

If you continue to see this message for an extended period, please check back later.

+
+ + + \ No newline at end of file diff --git a/install/error-pages/50x.html b/install/error-pages/50x.html new file mode 100644 index 0000000..c7e2585 --- /dev/null +++ b/install/error-pages/50x.html @@ -0,0 +1,80 @@ + + + + + + + Server Error + + + + +
+

Server Error

+

Sorry, something went wrong on our end while processing your request.

+
+

What you can try:

+ +
+

Error

+
+ + + \ No newline at end of file diff --git a/install/nginx-conf/10-error-pages.conf b/install/nginx-conf/10-error-pages.conf new file mode 100644 index 0000000..4c281e8 --- /dev/null +++ b/install/nginx-conf/10-error-pages.conf @@ -0,0 +1,58 @@ +# Global error pages +error_page 403 /403.html; +error_page 404 /404.html; +error_page 500 502 504 /50x.html; +error_page 503 /503.html; + +# Global error handler locations +location = /403.html { + internal; + try_files + $document_root/403.php + $document_root/403.html + /var/www/error-pages/403.php + /var/www/error-pages/403.html + =403; + fastcgi_intercept_errors on; +} + +location = /404.html { + internal; + try_files + $document_root/404.php + $document_root/404.html + /var/www/error-pages/404.php + /var/www/error-pages/404.html + =404; + fastcgi_intercept_errors on; +} + +location = /503.html { + internal; + try_files + $document_root/503.php + $document_root/503.html + /var/www/error-pages/503.php + /var/www/error-pages/503.html + =503; + fastcgi_intercept_errors on; +} + +location = /50x.html { + internal; + try_files + $document_root/50x.php + $document_root/50x.html + /var/www/error-pages/50x.php + /var/www/error-pages/50x.html + =500; + fastcgi_intercept_errors on; +} + +# PHP handling for error pages +location ~ ^/(?:403|404|503|50x)\.php$ { + internal; + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $request_filename; + fastcgi_pass unix:/var/run/php/php-fpm.sock; # Adjust this path as needed +} diff --git a/site-config.conf b/site-config.conf index 4a3b245..fb95af9 100644 --- a/site-config.conf +++ b/site-config.conf @@ -19,7 +19,7 @@ server { # Check for banned IPs if ($is_banned) { - return 403 "IP banned for bad behavior"; + return 403; } # Apply general rate limit