centos

怎样配置centos的lnmp虚拟主机

小樊
49
2025-09-12 00:28:45
栏目: 云计算

以下是在CentOS上配置LNMP虚拟主机的步骤:

一、安装LNMP环境

可以使用一键安装包或手动安装。以下以CentOS 7为例介绍一键安装:

  1. 下载安装包:wget -c http://soft.vpser.net/lnmp/lnmp0.5.tar.gz
  2. 解压:tar zxvf lnmp0.5.tar.gz
  3. 安装:cd lnmp0.5/,然后执行./centos.sh,按提示输入域名、MySQL root密码等信息。

二、手动配置虚拟主机

  1. 创建网站目录:如/home/wwwroot/yourdomain.com
  2. 创建虚拟主机配置文件:在/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;
    }
}
  1. 重启Nginx/etc/init.d/nginx restartsystemctl restart nginx

0
看了该问题的人还看了