溫馨提示×

centos lnmp虛擬主機配置

小樊
56
2025-09-03 23:52:41
欄目: 云計算

以下是在CentOS上配置LNMP虛擬主機的步驟:

環境準備

更新系統:sudo yum update -y。安裝Nginx、MySQL、PHP等基礎軟件,可參考中方法,如使用yum install -y nginx mariadb-server php php-fpm等命令。

配置虛擬主機

  • 使用命令行工具(推薦):安裝LNMP后,使用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。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女