温馨提示×

centos lnmp虚拟主机配置

小樊
64
2025-09-03 23:52:41
栏目: 云计算

以下是在CentOS上配置LNMP虚拟主机的步骤:

环境准备

更新系统:sudo yum update -y。安装Nginx、MySQL、PHP等基础软件,可参考中方法,如使用yum install -y nginx mariadb-server php php-fpm等命令。

配置虚拟主机

  • 使用命令行工具(推荐):安装LNMP后,使用lnmp vhost add命令,按提示输入域名、网站目录、是否启用伪静态、是否添加数据库等信息即可。
  • 手动配置:若要手动配置,需在/usr/local/nginx/conf/vhost/目录下创建以域名命名的.conf文件,如example.com.conf,并添加类似以下内容:
server {
    listen 80;
    server_name example.com;
    root /home/wwwroot/example.com;
    index index.html index.htm index.php;
    location / {
        try_files $uri $uri/ =404;
    }
    location ~ \.php$ {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
    }
    access_log /home/wwwlogs/example.com.log;
}

修改后需重启Nginx服务使配置生效:sudo systemctl restart nginx

0