How to setup a PHP file to return static files

22 hours ago 3
ARTICLE AD BOX

I am trying to use a single index.php file to protect static files created on docussaurus.

I created an NGINX config to force all links to be parsed by index.php like below:

server { listen 8000; root /var/www/blog/padroes/build; index index.html index.htm; server_name padroesaws.agregacontabil.com.br; access_log /var/log/nginx/padroes.access.log; error_log /var/log/nginx/padroes.error.log; location ~ /\. { deny all; } location / { include fastcgi_params; fastcgi_pass unix:/run/php/php8.4-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root/index.php; } }

This setup is working and even HTML files now are pre-processed by index.php using the code below:

<?php $headers = apache_request_headers(); foreach ($headers as $header => $value) { header('$header: $value'); } $filename = '/var/www/blog/padroes/build' . $_SERVER['DOCUMENT_URI']; if (is_file($filename)) { readfile($filename); } else { $filename = $filename . '/index.html'; readfile($filename); } ?>

But, when I try to return the static content my website seens without the CSS configuration like this:

enter image description here

Read Entire Article