# Nginx vhost for manthanaview.com (Bedrock). Adjust paths / PHP-FPM socket.
# Get certificates with:  certbot --nginx -d manthanaview.com -d www.manthanaview.com
server {
    listen 80;
    listen [::]:80;
    server_name manthanaview.com www.manthanaview.com;
    return 301 https://manthanaview.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.manthanaview.com;
    ssl_certificate     /etc/letsencrypt/live/manthanaview.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/manthanaview.com/privkey.pem;
    return 301 https://manthanaview.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name manthanaview.com;

    # Bedrock: the document root is the web/ folder, NOT the project root
    root /var/www/manthanaview/web;
    index index.php index.html;

    ssl_certificate     /etc/letsencrypt/live/manthanaview.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/manthanaview.com/privkey.pem;

    client_max_body_size 64M;

    # Never serve dotfiles, composer files or the config dir
    location ~ /\.(?!well-known) { deny all; }
    location ~* /(composer\.(json|lock)|wp-cli\.yml)$ { deny all; }

    # Prevent PHP scripts from being executed inside the uploads folder
    location ~* /app/uploads/.*\.php$ { deny all; }

    location / {
        try_files $uri $uri/ /index.php?$args;
    }

    # WordPress admin lives under /wp/
    rewrite ^/wp-admin/?$ /wp/wp-admin/ permanent;

    location ~ \.php$ {
        try_files $uri =404;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT   $realpath_root;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
        fastcgi_read_timeout 300;   # demo import + tagDiv Composer saves can be slow
    }

    location ~* \.(?:css|js|jpg|jpeg|gif|png|webp|svg|ico|woff2?|ttf)$ {
        expires 30d;
        access_log off;
        add_header Cache-Control "public";
    }
}
