在CentOS系统中,LNMP是指Linux、Nginx、MySQL和PHP的组合。下面是各个组件的配置文件详解:
主配置文件:
/etc/nginx/nginx.conf 站点配置文件:
/etc/nginx/conf.d/ 或 /etc/nginx/sites-available/ 下的文件 示例配置片段:
server { listen 80; server_name example.com www.example.com; root /var/www/html/example; index index.php index.html index.htm; location / { try_files $uri $uri/ =404; } location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 主配置文件:
/etc/my.cnf 或 /etc/mysql/my.cnf 示例配置片段:
[mysqld] bind-address = 127.0.0.1 port = 3306 datadir = /var/lib/mysql socket = /var/lib/mysql/mysql.sock character-set-server = utf8mb4 collation-server = utf8mb4_unicode_ci [client] default-character-set = utf8mb4 PHP-FPM配置文件:
/etc/php-fpm.d/www.conf PHP配置文件:
/etc/php.ini 示例配置片段(PHP-FPM):
[www] listen = /var/run/php-fpm/php-fpm.sock listen.owner = nginx listen.group = nginx pm = dynamic pm.max_children = 5 pm.start_servers = 2 pm.min_spare_servers = 1 pm.max_spare_servers = 3 SELinux配置:
/etc/selinux/configenforcing(启用)或disabled(禁用)。防火墙配置:
/etc/firewalld/ 或 /etc/sysconfig/iptablessystemctl restart nginx重启Nginx。通过以上配置,您可以在CentOS系统上搭建一个基本的LNMP环境。根据实际需求,您可能还需要进一步调整和优化各个组件的配置。