centos

centos lnmp配置文件详解

小樊
38
2025-05-07 02:54:55
栏目: 智能运维

在CentOS系统中,LNMP是指Linux、Nginx、MySQL和PHP的组合。下面是各个组件的配置文件详解:

1. Nginx配置文件

主配置文件:

站点配置文件:

示例配置片段:

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;
    }
}

2. MySQL配置文件

主配置文件:

示例配置片段:

[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

3. PHP配置文件

PHP-FPM配置文件:

PHP配置文件:

示例配置片段(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

4. 其他配置文件

注意事项:

通过以上配置,您可以在CentOS系统上搭建一个基本的LNMP环境。根据实际需求,您可能还需要进一步调整和优化各个组件的配置。

0
看了该问题的人还看了