2024-12-29 11:15:09 +08:00

84 lines
2.7 KiB
Plaintext

server {
listen 80;
# TODO Change next line. Set the domain.
server_name www.example.com;
# TODO Change next line. Set the document path which mounted in nginx container.
set $base /var/www/example.com;
# TODO Change next line. Set the path of the endpoint container's document.
set $container_path /var/www/html;
# TODO Change next line. Set the php cgi.
set $php_cgi "127.0.0.1:9000";
root $base;
# security headers
add_header X-XSS-Protection "1; mode=block" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Content-Security-Policy "default-src 'self' http: https: ws: wss: data: blob: 'unsafe-inline'; frame-ancestors 'self';" always;
add_header Permissions-Policy "interest-cohort=()" always;
# . files
location ~ /\.(?!well-known) {
deny all;
}
# logging
access_log /var/log/nginx/access.log combined buffer=512k flush=1m;
error_log /var/log/nginx/error.log warn;
# index.php
index index.php;
# gzip
gzip on;
gzip_vary on;
gzip_proxied any;
gzip_comp_level 6;
gzip_types text/plain text/css text/xml application/json application/javascript application/rss+xml application/atom+xml image/svg+xml;
# index.php fallback
location / {
try_files $uri $uri/ /index.php?$query_string;
}
# additional config# favicon.ico
location = /favicon.ico {
log_not_found off;
}
# robots.txt
location = /robots.txt {
log_not_found off;
}
# assets, media
location ~* \.(?:css(\.map)?|js(\.map)?|jpe?g|png|gif|ico|cur|heic|webp|tiff?|mp3|m4a|aac|ogg|midi?|wav|mp4|mov|webm|mpe?g|avi|ogv|flv|wmv)$ {
expires 7d;
}
# svg, fonts
location ~* \.(?:svgz?|ttf|ttc|otf|eot|woff2?)$ {
add_header Access-Control-Allow-Origin "*";
expires 7d;
}
# handle .php
location ~ \.php$ {
fastcgi_pass $php_cgi;
# 404
try_files $fastcgi_script_name =404;
# default fastcgi_params
include fastcgi_params;
# fastcgi settings
fastcgi_index index.php;
fastcgi_buffers 8 16k;
fastcgi_buffer_size 32k;
# fastcgi params
fastcgi_param DOCUMENT_ROOT $container_path;
fastcgi_param SCRIPT_FILENAME $container_path$fastcgi_script_name;
fastcgi_param PHP_ADMIN_VALUE "open_basedir=$container_path/:/usr/lib/php/:/tmp/";
}
}