以下是在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
。