| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- # 4核服务器:设置 4 个 worker(或 auto 自动检测)
- worker_processes auto;
- error_log /var/log/nginx/error.log warn;
- pid /var/run/nginx.pid;
- events {
- # 每个 worker 的最大连接数
- worker_connections 1024;
- # 同时接受多个连接
- multi_accept on;
- # 使用 epoll(Linux 高性能事件模型)
- use epoll;
- }
- http {
- include /etc/nginx/mime.types;
- default_type application/octet-stream;
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- access_log /var/log/nginx/access.log main;
- sendfile on;
- tcp_nopush on;
- tcp_nodelay on;
- keepalive_timeout 65;
- types_hash_max_size 2048;
- # Gzip 压缩
- gzip on;
- gzip_vary on;
- gzip_proxied any;
- gzip_comp_level 6;
- gzip_types text/plain text/css text/xml application/json application/javascript application/xml+rss application/atom+xml image/svg+xml;
- server {
- listen 8000;
- server_name _;
- root /app/public;
- index index.php index.html;
- # 请求体大小限制(上传文件)
- client_max_body_size 100M;
- # Laravel 路由
- location / {
- try_files $uri $uri/ /index.php?$query_string;
- }
- # Livewire v4 动态资源路由(如 /livewire-<hash>/livewire.js)
- # 这些 .js/.css 不是静态文件,必须回退到 Laravel 路由处理。
- # 量词 {8} 必须放在引号内,否则 Nginx 会把 { 当成配置块
- location ~ "^/livewire-[a-f0-9]{8}/" {
- 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 $realpath_root$fastcgi_script_name;
- include fastcgi_params;
- # 超时设置
- fastcgi_connect_timeout 60s;
- fastcgi_send_timeout 300s;
- fastcgi_read_timeout 300s;
- # 缓冲区设置
- fastcgi_buffer_size 128k;
- fastcgi_buffers 4 256k;
- fastcgi_busy_buffers_size 256k;
- }
- # 静态文件缓存
- location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
- try_files $uri =404;
- expires 1y;
- add_header Cache-Control "public, immutable";
- access_log off;
- }
- # 禁止访问隐藏文件
- location ~ /\. {
- deny all;
- }
- # 健康检查
- location /health {
- access_log off;
- return 200 "OK";
- add_header Content-Type text/plain;
- }
- }
- }
|