Laravel 与 Linux 服务器性能调优秘籍
一 基础环境优化
二 Linux 系统与网络内核调优
www-data soft nofile 1048576
www-data hard nofile 1048576
www-data soft nproc 65535
www-data hard nproc 65535
fs.file-max = 2097152
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_keepalive_time = 600
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 5
vm.swappiness = 10
应用:sysctl --system。三 PHP 与 FPM 关键配置
opcache.enable=1
opcache.enable_cli=1
opcache.memory_consumption=512M
opcache.interned_strings_buffer=64M
opcache.max_accelerated_files=10000
opcache.revalidate_freq=60
opcache.jit=tracing
opcache.jit_buffer_size=256M
四 Laravel 框架与数据库优化
php artisan config:cache、php artisan route:cache、php artisan view:cache(开发环境勿用)。五 Nginx 与压测上线
location ~* \.(ico|css|js|gif|jpe?g|png|svg|woff2?|ttf|map)$ {
access_log off;
expires 30d;
add_header Cache-Control "public, max-age=2592000, immutable";
try_files $uri =404;
}
location / {
try_files $uri $uri/ @octane;
}
location @octane {
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_read_timeout 60s;
proxy_connect_timeout 3s;
proxy_send_timeout 60s;
proxy_pass http://127.0.0.1:8000;
}