linux

LNMP配置文件怎么写

小樊
52
2025-09-10 07:41:03
栏目: 编程语言

LNMP配置文件主要包括Nginx、MySQL和PHP-FPM的配置,以下是各部分配置文件的关键内容及示例:

Nginx配置文件

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
    worker_connections 1024;
}
http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    sendfile on;
    # 其他HTTP相关配置
}
server {
    listen 80;
    server_name 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/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
}

MySQL配置文件

[mysqld]
server-id = 1
bind-address = 127.0.0.1
port = 3306
datadir = /var/lib/mysql
character-set-server = utf8
default-storage-engine = INNODB
innodb_data_file_path = ibdata1:12M:autoextend
innodb_log_file_size = 5M
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 1
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock

PHP-FPM配置文件

[global]
pid = /run/php/php7.4-fpm.pid
error_log = /var/log/php7.4-fpm.log
log_level = notice
emergency_restart_threshold = 5
emergency_restart_interval = 60
[www]
user = www-data
group = www-data
listen = /run/php/php7.4-fpm.sock
pm = dynamic
pm.max_children = 15
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 4

0
看了该问题的人还看了