以下是在CentOS上配置LNMP虚拟主机的步骤:
更新系统:sudo yum update -y。安装Nginx、MySQL、PHP等基础软件,可参考中方法,如使用yum install -y nginx mariadb-server php php-fpm等命令。
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。