# Nginx主配置文件优化(/www/server/nginx/conf/nginx.conf)
worker_processes auto; # 自动匹配CPU核心数
worker_rlimit_nofile 65535;
events {
worker_connections 4096;
use epoll;
multi_accept on;
}
# PHP-FPM配置(/www/server/php/{version}/etc/php-fpm.conf)
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 20
pm.max_requests = 1024
# Apache主配置(/www/server/apache/conf/httpd.conf)
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxRequestWorkers 150
MaxConnectionsPerChild 1000
# 启用MPM Event模块
<IfModule mpm_event_module>
ServerLimit 16
ThreadsPerChild 64
</IfModule>
# my.cnf优化建议
[mysqld]
innodb_buffer_pool_size = 1G # 建议为物理内存的50-70%
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2 # 非关键业务可设为2提升性能
query_cache_size = 64M
; php.ini优化
opcache.enable=1
opcache.memory_consumption=128
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
upload_max_filesize = 50M
post_max_size = 52M
max_execution_time = 300
502 Bad Gateway
数据库连接问题
性能瓶颈定位
通过宝塔面板可以方便地监控服务器状态、管理定时任务和设置自动备份,建议充分利用这些功能来维护服务器稳定运行。