配置CentOS LNMP虚拟主机有使用命令和手动配置两种方法,以下为你分别介绍:
wget
命令下载LNMP一键安装包,然后解压并执行安装脚本,如wget http://soft.vpser.net/lnmp/lnmp1.9.tar.gz -cO lnmp1.9.tar.gz && tar zxf lnmp1.9.tar.gz && cd lnmp1.9 && ./install.sh lnmp
。lnmp vhost add
命令,按提示输入域名、网站目录、是否启用伪静态、日志等信息。mkdir -p /home/wwwroot/虚拟主机域名
。/usr/local/nginx/conf/vhost/
目录下创建以域名命名的.conf
文件,如vi /usr/local/nginx/conf/vhost/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 unix:/tmp/php-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
}
systemctl restart nginx
使配置生效。