| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- # 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 serves assets through Laravel routes such as
- # /livewire/livewire.min.js or /livewire-bb2e0a45/livewire.js, so these
- # must not be swallowed by the generic static .js/.css location below.
- location ^~ /livewire/ {
- try_files $uri $uri/ /index.php?$query_string;
- }
- location ^~ /livewire- {
- try_files $uri $uri/ /index.php?$query_string;
- }
- # Livewire update endpoint (POST /livewire/update or any /livewire/* path)
- # must be routed to PHP, not caught by static file rules.
- location ~ ^/livewire(/|$) {
- 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)$ {
- 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;
- }
- }
- }
|