LNMP是指Linux、Nginx、MySQL和PHP组成的网站架构,常用于中小型网站服务。在Debian上配置LNMP环境时,以下是一些最佳实践:
sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo apt install mariadb-server mariadb-client
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
sudo apt install php-fpm php-mysql
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
listen
行,修改为:listen /run/php/php7.4-fpm.sock
sudo systemctl restart php7.4-fpm
sudo nano /etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html index.htm index.nginx-debian.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
sudo nginx -t
sudo systemctl restart nginx
sudo nano /var/www/html/index.php
<?php
phpinfo();
?>
worker_processes auto;
worker_cpu_affinity auto;
worker_rlimit_nofile 65535;
http {
sendfile on;
sendfile_max_chunk 512k;
关闭压缩;
fastcgi_read_timeout 300000;
tcp_nodelay on;
keepalive_timeout 65;
keepalive_requests 100000;
server_tokens off;
}
opcache.enable=1;
opcache.interned_strings_buffer=64;
opcache.max_accelerated_files=10000;
opcache.memory_consumption=256;
opcache.save_comments=1;
opcache.fast_shutdown=1;
opcache.validate_timestamps=1;
opcache.fast_shutdown=1;
ulimit -n 65535
sysctl -w net.core.somaxconn=65535
sysctl -w net.ipv4.ip_local_port_range="1024 65535"
sysctl -w net.ipv4.tcp_fin_timeout="30"
sysctl -w net.ipv4.tcp_slow_start_after_idle="0"
sysctl -w net.ipv4.tcp_fastopen=3
sysctl -w net.ipv4.tcp_syncookies=1
sysctl -w net.core.netdev_max_backlog=65535
sysctl -w net.netfilter.nf_conntrack_max=2097152
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_fin_wait=60
sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=60
以上步骤和优化措施可以帮助你在Debian上成功配置和优化LNMP环境。