在CentOS上配置LNMP(Linux, Nginx, MySQL/MariaDB, PHP)环境是一个常见的任务,用于托管Web应用程序。以下是一些基本的配置技巧和步骤:
首先,确保你的系统是最新的,然后安装Nginx:
yum update
yum install nginx
安装完成后,启动Nginx并设置开机自启动:
systemctl start nginx
systemctl enable nginx
Nginx的主要配置文件通常位于/etc/nginx/nginx.conf
。在这个文件中,你可以设置监听端口、服务器块、静态文件目录等。
server {
listen 80;
server_name example.com;
root /var/www/html;
index index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
error_page 404 /404.html;
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
确保PHP-FPM正在运行,并配置Nginx以使用它:
systemctl start php-fpm
systemctl enable php-fpm
在Nginx配置文件中,找到处理PHP文件的部分,并确保fastcgi_pass
指向PHP-FPM的正确监听地址和端口。
worker_processes
为服务器的CPU核心数。以上就是在CentOS上配置LNMP环境的一些基本技巧和步骤。请根据你的具体需求和环境进行调整。