nginx.conf 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. # Livewire update endpoint (POST /livewire/update or any /livewire/* path)
  52. # must be routed to PHP, not caught by static file rules.
  53. location ~ ^/livewire(/|$) {
  54. try_files $uri $uri/ /index.php?$query_string;
  55. }
  56. # PHP-FPM 处理
  57. location ~ \.php$ {
  58. fastcgi_pass 127.0.0.1:9000;
  59. fastcgi_index index.php;
  60. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  61. include fastcgi_params;
  62. # 超时设置
  63. fastcgi_connect_timeout 60s;
  64. fastcgi_send_timeout 300s;
  65. fastcgi_read_timeout 300s;
  66. # 缓冲区设置
  67. fastcgi_buffer_size 128k;
  68. fastcgi_buffers 4 256k;
  69. fastcgi_busy_buffers_size 256k;
  70. }
  71. # 静态文件缓存
  72. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  73. expires 1y;
  74. add_header Cache-Control "public, immutable";
  75. access_log off;
  76. }
  77. # 禁止访问隐藏文件
  78. location ~ /\. {
  79. deny all;
  80. }
  81. # 健康检查
  82. location /health {
  83. access_log off;
  84. return 200 "OK";
  85. add_header Content-Type text/plain;
  86. }
  87. }
  88. }