nginx.conf 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # PHP-FPM 处理
  43. location ~ \.php$ {
  44. fastcgi_pass 127.0.0.1:9000;
  45. fastcgi_index index.php;
  46. fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
  47. include fastcgi_params;
  48. # 超时设置
  49. fastcgi_connect_timeout 60s;
  50. fastcgi_send_timeout 300s;
  51. fastcgi_read_timeout 300s;
  52. # 缓冲区设置
  53. fastcgi_buffer_size 128k;
  54. fastcgi_buffers 4 256k;
  55. fastcgi_busy_buffers_size 256k;
  56. }
  57. # 静态文件缓存
  58. location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
  59. expires 1y;
  60. add_header Cache-Control "public, immutable";
  61. access_log off;
  62. }
  63. # 禁止访问隐藏文件
  64. location ~ /\. {
  65. deny all;
  66. }
  67. # 健康检查
  68. location /health {
  69. access_log off;
  70. return 200 "OK";
  71. add_header Content-Type text/plain;
  72. }
  73. }
  74. }