centos

如何配置centos lnmp的虚拟主机

小樊
50
2025-08-16 21:30:37
栏目: 云计算

配置CentOS LNMP虚拟主机有使用命令和手动配置两种方法,以下为你分别介绍:

使用命令配置

  1. 安装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
  2. 添加虚拟主机:安装完成后,执行lnmp vhost add命令,按提示输入域名、网站目录、是否启用伪静态、日志等信息。

手动配置

  1. 创建网站根目录:如mkdir -p /home/wwwroot/虚拟主机域名
  2. 创建虚拟主机配置文件:在/usr/local/nginx/conf/vhost/目录下创建以域名命名的.conf文件,如vi /usr/local/nginx/conf/vhost/example.com.conf
  3. 编辑配置文件:在文件中添加如下内容:
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;
    }
}
  1. 重启Nginx:执行systemctl restart nginx使配置生效。

0
看了该问题的人还看了