一、安装Niginx
Nginx是一个高性能http服务器,和反向代理器
打开https://nginx.org/en/download.html下载
#下载nginx安装包
yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel
cd /usr/local
mkdir nginx
cd nginx
wget http://nginx.org/download/nginx-1.16.1.tar.gz
tar -xvf nginx-1.16.1.tar.gz
#编译安装
cd /usr/local/nginx-1.16.1
./configure --prefix=/usr/local/nginx/ #--prefix指定编译目录
./configure --prefix=/usr/local/nginx/ --with-http_realip_module --with-http_image_filter_module=dynamic --with-http_ssl_module #--with指定编译模块
make & make install
#开启模块并查看进程
./sbin/nginx #用sbin目录下的二进制文件启动nginx
ps -ef | grep nginx
#在游览器里输入ip看到welcome to nginx即可
二、第一个静态web服务
htm文件 | 默认发布页面 |
---|---|
conf文件 | 配置文件目录 |
sed -i '/^[[:space:]]*#/'d nginx.conf #去掉文件中的#注释
可以分为几个逻辑部分
http部分、server部分、location部分。而且他们由层级关系,http中可以配置多个server,一个server中可以配置多个location,
Nginx最基本的功能就是提供http服务。
如果需要一个nginx主机提供多个http服务,每一个server就代表一个http服务,可以配置多个server服务提供多个http服务
可以通过location将url中的路径和服务器的某个目录建立联系。
location / {
root html;
#当前location所对应文档的根目录为html
index index.html index.htm;
#没有指定资源默认发布默认页面
}