# ==============================================================================
# Aksara CMS - Production Nginx Server Block Configuration
# ==============================================================================
server {
# Set absolute path to your current project's public directory
set $public_dir "/path/to/aksaracms/public";
listen 8081;
server_name localhost;
root $public_dir;
index index.php index.html index.htm;
# Max upload file size limit
client_max_body_size 64M;
# Enforce NO www
if ($host ~* ^www\.(.*)) {
set $host_without_www $1;
rewrite ^/(.*)$ $scheme://$host_without_www/$1 permanent;
}
# Removes trailing "index" from all controllers
if ($request_uri ~* index/?$) {
rewrite ^/(.*)/index/?$ /$1 permanent;
}
# Removes trailing slashes (prevents SEO duplicate content issues)
if (!-d $request_filename) {
rewrite ^/(.+)/$ /$1 permanent;
}
# --------------------------------------------------------------------------
# 1. GZIP Compression (Reduces network payload up to 70%)
# --------------------------------------------------------------------------
gzip on;
gzip_disable "msie6";
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types
text/plain
text/css
text/xml
text/javascript
application/json
application/javascript
application/x-javascript
application/xml
application/xml+rss
image/svg+xml;
# --------------------------------------------------------------------------
# 2. Browser Caching (1 Year Max-Age for Lighthouse Performance Score)
# --------------------------------------------------------------------------
location ~* \.(ico|jpe?g|png|gif|webp|svg|css|js|woff2?|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, max-age=31536000, immutable";
access_log off;
log_not_found off;
}
# --------------------------------------------------------------------------
# 3. Security (Prevent PHP execution inside uploads directory)
# --------------------------------------------------------------------------
location ^~ /uploads/ {
location ~ \.php$ {
deny all;
}
}
# Unless the request is for a valid file (image, js, css, etc.), send to bootstrap
if (!-e $request_filename) {
rewrite ^/(.*)$ /index.php?/$1 last;
break;
}
# Catch all
error_page 404 /index.php;
# --------------------------------------------------------------------------
# 4. Use fastcgi for all php files
# --------------------------------------------------------------------------
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
# fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $public_dir/$fastcgi_script_name;
include fastcgi_params;
# Increase timeouts for long-running scripts (geospatial/image generation)
fastcgi_read_timeout 300;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 300;
}
# Deny access to apache .htaccess files & hidden files
location ~ /\.ht {
deny all;
}
location ~ /\. {
deny all;
}
}
|