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
  • 测试:
    在这里插入图片描述
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/hg666hh/article/details/88194902