61 lines
1.4 KiB
Nginx Configuration File
61 lines
1.4 KiB
Nginx Configuration File
server {
|
|
listen 80 default_server;
|
|
listen [::]:80 default_server;
|
|
server_name _;
|
|
|
|
root /var/www/public;
|
|
index index.html index.php;
|
|
|
|
client_max_body_size 20M;
|
|
|
|
# 前端 SPA fallback
|
|
location = /index.html {
|
|
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
|
add_header Pragma "no-cache";
|
|
expires 0;
|
|
try_files $uri =404;
|
|
}
|
|
|
|
location / {
|
|
try_files $uri $uri/ /index.html;
|
|
}
|
|
|
|
# API 路由
|
|
location /api/ {
|
|
try_files $uri $uri/ /index.php?$query_string;
|
|
}
|
|
|
|
# PHP-FPM
|
|
location ~ \.php$ {
|
|
fastcgi_pass 127.0.0.1:9000;
|
|
fastcgi_index index.php;
|
|
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
|
|
include fastcgi_params;
|
|
fastcgi_param HTTP_AUTHORIZATION $http_authorization;
|
|
fastcgi_hide_header X-Powered-By;
|
|
}
|
|
|
|
# 静态资源缓存
|
|
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
|
|
expires 30d;
|
|
add_header Cache-Control "public, immutable";
|
|
}
|
|
|
|
# 安全:禁止访问敏感文件
|
|
location ~ /\. {
|
|
deny all;
|
|
}
|
|
location ~* \.(env|sql|log|md|gitignore)$ {
|
|
deny all;
|
|
}
|
|
location ~* ^/(storage/cache|storage/logs)/ {
|
|
deny all;
|
|
}
|
|
|
|
# 禁止访问源代码目录
|
|
location ~* ^/(app|config|routes|database|vendor)/ {
|
|
deny all;
|
|
return 404;
|
|
}
|
|
}
|