nginx.conf 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. server {
  2. listen 80;
  3. server_name bot28api.sp2509.cc;
  4. root /var/www/html/public; # 必须指向 public 目录
  5. index index.php index.html;
  6. location / {
  7. add_header 'Access-Control-Allow-Origin' '*';
  8. add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
  9. add_header 'Access-Control-Allow-Headers' 'Content-Type, Authorization';
  10. add_header 'Access-Control-Allow-Credentials' 'true';
  11. add_header 'Access-Control-Max-Age' 3600;
  12. if ($request_method = 'OPTIONS') {
  13. # OPTIONS 请求直接返回 200
  14. return 204;
  15. }
  16. #try_files $uri $uri/ /index.php?$query_string;
  17. if (!-e $request_filename) {
  18. rewrite ^/index.php(.*)$ /index.php?s=$1 last;
  19. rewrite ^(.*)$ /index.php?s=$1 last;
  20. break;
  21. }
  22. }
  23. # ===== PHP 解析配置(强制指向 8.4,避免版本问题)=====
  24. location ~ \.php$ {
  25. fastcgi_pass app:9000; # 确认是 8.4 的 sock 文件
  26. fastcgi_index index.php;
  27. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  28. fastcgi_param DOCUMENT_ROOT $realpath_root;
  29. include fastcgi_params;
  30. }
  31. # ===== 禁止访问敏感文件/目录(保留)=====
  32. location ~ /\.(?!well-known).* {
  33. deny all;
  34. }
  35. location ~ ^/(\.user.ini|\.htaccess|\.git|\.env) {
  36. return 404;
  37. }
  38. # ===== 静态文件缓存(保留,不影响接口)=====
  39. location ~* \.(jpg|jpeg|png|gif|ico|css|js)$ {
  40. expires 30d;
  41. add_header Cache-Control "public, max-age=2592000";
  42. access_log off;
  43. }
  44. # ===== 日志配置(保留)=====
  45. access_log /var/log/nginx/bot28api.sp2509.cc.log;
  46. error_log /var/log/nginx/bot28api.sp2509.cc.error.log;
  47. }