nginx.conf 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # 4核服务器:设置 4 个 worker(或 auto 自动检测)
  2. worker_processes auto;
  3. error_log /var/log/nginx/error.log warn;
  4. pid /var/run/nginx.pid;
  5. events {
  6. # 每个 worker 的最大连接数
  7. worker_connections 1024;
  8. # 同时接受多个连接
  9. multi_accept on;
  10. # 使用 epoll(Linux 高性能事件模型)
  11. use epoll;
  12. }
  13. http {
  14. include /etc/nginx/mime.types;
  15. default_type application/octet-stream;
  16. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  17. '$status $body_bytes_sent "$http_referer" '
  18. '"$http_user_agent" "$http_x_forwarded_for"';
  19. access_log /var/log/nginx/access.log main;
  20. sendfile on;
  21. tcp_nopush on;
  22. tcp_nodelay on;
  23. keepalive_timeout 65;
  24. types_hash_max_size 2048;
  25. # Gzip 压缩
  26. gzip on;
  27. gzip_vary on;
  28. gzip_proxied any;
  29. gzip_comp_level 6;
  30. gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
  31. server {
  32. listen 8000;
  33. server_name _;
  34. root /app/public;
  35. index index.php index.html;
  36. # 请求体大小限制(上传文件)
  37. client_max_body_size 100M;
  38. # Laravel 路由
  39. location / {
  40. try_files $uri $uri/ /index.php?$query_string;
  41. }
  42. # Livewire serves assets through Laravel routes such as
  43. # /livewire/livewire.min.js or /livewire-bb2e0a45/livewire.js, so these
  44. # must not be swallowed by the generic static .js/.css location below.
  45. location ^~ /livewire/ {
  46. try_files $uri $uri/ /index.php?$query_string;
  47. }
  48. location ^~ /livewire- {
  49. try_files $uri $uri/ /index.php?$query_string;
  50. }
  51. # PHP-FPM 处理
  52. location ~ \.php$ {
  53. fastcgi_pass 127.0.0.1:9000;
  54. fastcgi_index index.php;
  55. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  56. include fastcgi_params;
  57. # 超时设置
  58. fastcgi_connect_timeout 60s;
  59. fastcgi_send_timeout 300s;
  60. fastcgi_read_timeout 300s;
  61. # 缓冲区设置
  62. fastcgi_buffer_size 128k;
  63. fastcgi_buffers 4 256k;
  64. fastcgi_busy_buffers_size 256k;
  65. }
  66. # 静态文件缓存
  67. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  68. expires 1y;
  69. add_header Cache-Control "public, immutable";
  70. access_log off;
  71. }
  72. # 禁止访问隐藏文件
  73. location ~ /\. {
  74. deny all;
  75. }
  76. # 健康检查
  77. location /health {
  78. access_log off;
  79. return 200 "OK";
  80. add_header Content-Type text/plain;
  81. }
  82. }
  83. }