35 lines
1.2 KiB
Plaintext
35 lines
1.2 KiB
Plaintext
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
root /var/www/html;
|
|
index index.php index.html index.htm;
|
|
|
|
# Custom 404 error page setup
|
|
error_page 404 /404.php;
|
|
|
|
# 1. Block to handle static files directly
|
|
# This location handles assets that should NOT be passed to index.php
|
|
# (e.g., CSS, JS, images, fonts).
|
|
# You can expand this regex (e.g., |woff|ttf|svg)
|
|
location ~* \.(jpg|jpeg|gif|png|ico|css|js)$ {
|
|
try_files $uri =404; # Serve the file if found, otherwise return a 404
|
|
}
|
|
|
|
# 2. Main location block (Front Controller Pattern)
|
|
location / {
|
|
# Check if the requested URI ($uri) exists as a file or directory.
|
|
# If not, rewrite the request internally to index.php,
|
|
# preserving original query arguments ($args).
|
|
try_files $uri $uri/ /index.php?$args;
|
|
}
|
|
|
|
# 3. Block to pass PHP scripts to PHP-FPM
|
|
location ~ \.php$ {
|
|
# This remains the same to execute any file ending in .php
|
|
fastcgi_pass app:9000; # 'app' is the name of your PHP-FPM service
|
|
fastcgi_index index.php;
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
fastcgi_param PATH_INFO $fastcgi_path_info;
|
|
}
|
|
} |