以下是在CentOS上配置LNMP虚拟主机的步骤:
一、安装LNMP环境
可以使用一键安装包或手动安装。以下以CentOS 7为例介绍一键安装:
- 下载安装包:
wget -c http://soft.vpser.net/lnmp/lnmp0.5.tar.gz。 - 解压:
tar zxvf lnmp0.5.tar.gz。 - 安装:
cd lnmp0.5/,然后执行./centos.sh,按提示输入域名、MySQL root密码等信息。
二、手动配置虚拟主机
- 创建网站目录:如
/home/wwwroot/yourdomain.com。 - 创建虚拟主机配置文件:在
/usr/local/nginx/conf/vhost/下创建yourdomain.com.conf,内容示例:
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
root /home/wwwroot/yourdomain.com;
index index.html index.htm index.php;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/tmp/php-cgi.sock;
}
}
- 重启Nginx:
/etc/init.d/nginx restart或systemctl restart nginx。