Nginx学习:搭建Nginx服务器并配置虚拟主机(Cent7)

一、搭建Nginx服务器

  • 安装PCRE库:
yum install  pcre pcre-devel -y
  • 下载源码:
wget -c http://nginx.org/download/nginx-1.15.9.tar.gz
  • 解压并安装:
tar -xzf nginx-1.15.9.tar.gz -C /usr/src/
useradd www
cd nginx-1.15.9
./configure  --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
  • 启动Nginx:
/usr/local/nginx/sbin/nginx
  • 查看Nginx进程:

在这里插入图片描述

  • 通过浏览器访问:

在这里插入图片描述

二、配置虚拟主机

  • 编辑nginx.conf文件(/usr/local/nginx/conf目录下):

在这里插入图片描述

  • 创建test1、test2目录,并在两个目录中创建网站页面:
mkdir -p /usr/local/nginx/html/test{1,2}
echo 'this is test1' >> /usr/local/nginx/html/test1/index.html
echo 'this is test2' >> /usr/local/nginx/html/test2/index.html
  • 编辑本地hosts文件:

在这里插入图片描述

  • 重启nginx:
pkill nginx
/usr/local/nginx/sbin/nginx
  • 测试:
    在这里插入图片描述
    在这里插入图片描述
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值