配置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
使配置生效。