101 lines
3.5 KiB
Nginx Configuration File
101 lines
3.5 KiB
Nginx Configuration File
# Example nginx config
|
|
# for serving tkr as a subdomain without SSL
|
|
# e.g. http://tkr.my-domain.com/
|
|
#
|
|
# NOTE: Do not use in production.
|
|
# This is provided for docker compose
|
|
# (The included docker-compose file will mount it in the container image)
|
|
server {
|
|
listen 80;
|
|
server_name localhost;
|
|
|
|
root /var/www/tkr/public;
|
|
index index.php;
|
|
|
|
# Security headers
|
|
# The first rule is to prevent including in a frame on a different domain.
|
|
# Remove it if you want to do that.
|
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
|
|
# Deny access to hidden files
|
|
location ~ /\. {
|
|
deny all;
|
|
access_log off;
|
|
log_not_found off;
|
|
}
|
|
|
|
# PHP routing - everything goes through index.php
|
|
location / {
|
|
# Cache static files
|
|
# Note that I don't actually serve most of this (just css)
|
|
# but this prevents requests for static content from getting to the PHP handler.
|
|
#
|
|
# I've excluded /css/custom so that requests for uploaded css can be handled by the PHP app.
|
|
# That lets me store uploaded content outside of the document root,
|
|
# so it isn't served directly.
|
|
|
|
# CSS files - 1 hour cache
|
|
location ~* ^/(?!css/custom/).+\.css$ {
|
|
expires 1h;
|
|
add_header Cache-Control "public";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# Other static assets - 1 year cache
|
|
location ~* ^/.+\.(js|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 1y;
|
|
add_header Cache-Control "public, immutable";
|
|
try_files $uri =404;
|
|
}
|
|
|
|
# index.php is the entry point
|
|
# It needs to be sent to php-fpm
|
|
# But if someone tries to directly access index.php, that file will throw a 404
|
|
# so bots and scanners can't tell this is a php app
|
|
location = /index.php {
|
|
# If you're running php-fpm on the same server as nginx,
|
|
# then change this to the local php-fpm socket
|
|
# e.g. fastcgi_pass unix:/run/php/php8.2-fpm.sock;
|
|
fastcgi_pass php:9000;
|
|
fastcgi_param SCRIPT_FILENAME /var/www/tkr/public/index.php;
|
|
include fastcgi_params;
|
|
|
|
fastcgi_param REQUEST_METHOD $request_method;
|
|
fastcgi_param REQUEST_URI $request_uri;
|
|
fastcgi_param QUERY_STRING $query_string;
|
|
}
|
|
|
|
# Block attempts to access all other .php files directly
|
|
# (these are bots and scanners)
|
|
location ~ ^/.+\.php$ {
|
|
return 404;
|
|
}
|
|
|
|
# forward other requests to the fallback block,
|
|
# which sends them to php-fpm for handling
|
|
try_files $uri $uri/ @tkr_fallback;
|
|
}
|
|
|
|
# Fallback for /tkr routing - all non-file requests (e.g. /login) go to index.php
|
|
location @tkr_fallback {
|
|
# If you're running php-fpm on the same server as nginx,
|
|
# then change this to the local php-fpm socket
|
|
# e.g. fastcgi_pass unix:/run/php/php8.2-fpm.sock;
|
|
fastcgi_pass php:9000;
|
|
fastcgi_param SCRIPT_FILENAME /var/www/tkr/public/index.php;
|
|
include fastcgi_params;
|
|
|
|
fastcgi_param REQUEST_METHOD $request_method;
|
|
fastcgi_param REQUEST_URI $request_uri;
|
|
fastcgi_param QUERY_STRING $query_string;
|
|
}
|
|
|
|
# Deny access to sensitive directories
|
|
location ~ ^/(storage|src|templates|uploads|config) {
|
|
deny all;
|
|
return 404;
|
|
}
|
|
}
|