Ubuntu LNMP(Linux, Nginx, MySQL/MariaDB, PHP)环境的安全设置是确保服务器稳定性和数据安全的关键。以下是一些重要的安全设置要点:
/etc/ssh/sshd_config 文件,将默认端口从22改为非标准端口(如2222)。sudo systemctl restart sshd。/etc/hosts.allow 和 /etc/hosts.deny:限制允许登录的IP。allowusers 指令:在 /etc/ssh/sshd_config 文件中指定允许登录的用户。sudo apt-get install ufw。sudo ufw enable。sudo ufw allow 2222/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow 3306/tcp
sudo ufw reload。/etc/nginx/nginx.conf 或 /etc/nginx/sites-available/default。sudo systemctl restart nginx。/etc/php/7.x/fpm/php.ini(具体版本可能有所不同)。display_errors 为 On:便于开发过程中显示错误信息。error_reporting 为 E_ALL:报告所有错误。sudo systemctl restart php7.x-fpm。mysql_secure_installation 脚本:设置强密码、删除匿名用户、禁止远程root登录等。/etc/mysql/mysql.conf.d/mysqld.cnf 中的 bind-address 设置为 0.0.0.0 以允许远程连接,然后注释掉这一行。sudo systemctl restart mysql。sudo apt-get install phpmyadmin。/usr/share/phpmyadmin 目录。sudo apt update && sudo apt upgrade。通过上述措施,可以显著提高Ubuntu LNMP环境的安全性,减少遭受攻击的风险。建议用户定期检查和更新安全配置,以应对不断变化的安全威胁。