Nginx-----系列(二)

简介: nginx是C语言开发,建议在Linux上运行,我使用的是CentOS8作为安装环境。

1.Nginx下载与安装

1.1 Nginx下载

    官网下载Nginx软件 http://nginx.org/

1.2 Nginx 的源码安装

    nginx是C语言开发,建议在Linux上运行,我使用的是CentOS8作为安装环境。

 1.gcc

   安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装  gcc。

yum install -y gcc make automake

2345_image_file_copy_176.jpg

2345_image_file_copy_177.jpg

2.PCRE

   PCRE(Perl Compatible Regular Expressions)是一个Perl库,包括 Perl 兼容的正则表达式库。  nginx的http模块使用Pcre来解析正则表达式,所以需要在Linux上安装Pcre库。

yum install -y pcre pcre-devel

2345_image_file_copy_178.jpg

2345_image_file_copy_179.jpg

注:pcre-devel是使用pcre开发的一个二次开发库。nginx也需要此库。

3.zlib

   zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库。

yum install -y zlib zlib-devel

2345_image_file_copy_180.jpg

2345_image_file_copy_181.jpg

4.Openssl

  OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在Linux安装openssl库。

yum install -y openssl openssl-devel

2345_image_file_copy_182.jpg

2345_image_file_copy_183.jpg

5.统一安装依赖环境命令:

yum -y install gcc make automake pcre-devel zlib zlib-devel openssl openssl-
devel

2.1 安装 Nginx

1.创建存放源文件的文件夹

  首先创建apps目录,用于存放源文件以及解压后的文件

2.上传Nginx到步骤1创建的目录下

3.解压 Nginx

注: 如果想直接拖到Linux中  需要安装: yum install lrzsz -y

2345_image_file_copy_184.jpg

[root@localhost apps]# pwd
/opt/apps
[root@localhost apps]# ls
nginx-1.20.1.tar.gz
[root@localhost apps]# tar -zxvf nginx-1.20.1.tar.gz (解压)
[root@localhost apps]# cd nginx-1.20.1

2345_image_file_copy_185.jpg

进入到 Nginx 解压包目录  /apps/nginx-1.20.1 目录中,查看 Nginx 的目录。

其中各个目录中存放的文件作用为:

2345_image_file_copy_186.jpg

l auto:存放 Nginx 自动安装的相关文件
l conf:存放 Nginx 服务器配置文件
l configure:命令,用于对即将安装的软件的配置,完成 makefile 编译文件的生成
l contrib:存放由其他机构贡献的文档材料
l html:存放 Nginx 欢迎页面
l man:manual,手册,存放 Nginx 帮助文档
l src:存放 Nginx 源码

Nginx里面的基本信息的配置

2345_image_file_copy_187.jpg

--prefix:Nginx 安装目录。注意,安装目录与解压目录不一样
--sbin-path:Nginx 命令文件
--modules-path:Nginx 模块存放路径
--conf-prefix:Nginx 配置文件存放路径
--pid-path:Nginx 的进程 id 文件
--error-log-path:错误日志文件
--http-log-path:http访问日志文件

其中 --with......   为没有安装的文件

查询方法:  ./configure --help|grep with-    那如何安装呢: ./configure --with-select_module

2345_image_file_copy_188.jpg

配置模块  注: /var/temp/nginx/client目录需要手动创建

2345_image_file_copy_189.jpg

2345_image_file_copy_190.jpg

2345_image_file_copy_191.jpg

[root@localhost nginx-1.20.1]# mkdir -p /var/temp/nginx/client
[root@localhost nginx-1.20.1]# pwd
/opt/apps/nginx-1.20.1
[root@localhost nginx-1.20.1]# ./configure \
--prefix=/usr/local/nginx \
--pid-path=/usr/local/nginx/logs/nginx.pid \
--error-log-path=/usr/local/nginx/logs/error.log \
--http-log-path=/usr/local/nginx/logs/access.log \
--with-http_ssl_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi

编译安装

 这是两个命令,make 为编译命令,make install 为安装命令,可以分别执行。这里使用&&将两个命令连接执行,会在前面命令执行成功的前提下才会执行第二个命令。

make && make install

安装完成 里面会多一个nginx

2345_image_file_copy_192.jpg

2345_image_file_copy_193.jpg

在nginx中这几个目录的作用

2345_image_file_copy_194.jpg

Nginx目录介绍

   conf目录

       Nginx所有配置文件的目录,极其重要。在该目录中包含一个nginx.conf配置文件。

  html目录

  Nginx的默认站点目录。

   logs目录

     存放Nginx的日志文件。 access.log error.log

  sbin目录

    Nginx命令的目录,如Nginx的启动命令。

目录
相关文章
|
5月前
|
应用服务中间件 Apache 数据库
Nginx(一)
Nginx(一)
|
8月前
|
缓存 负载均衡 安全
|
9月前
|
负载均衡 JavaScript 应用服务中间件
nginx使用
nginx使用
|
9月前
|
缓存 负载均衡 应用服务中间件
Nginx(一)
Nginx(一)
86 0
|
9月前
|
前端开发 安全 应用服务中间件
|
负载均衡 应用服务中间件 nginx
|
缓存 负载均衡 Unix
Nginx系列——初识
Nginx系列——初识
88 1
|
负载均衡 监控 算法
Nginx 的使用
1、Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。 2、Nginx是一款轻量级的Web服务器/反向代理服务器以及电子邮件代理服务器,并在一个BSD-like协议下发行。
|
缓存 负载均衡 算法
Nginx——详解
Nginx是lgor Sysoev为俄罗斯访问量第二的rambler.ru站点设计开发的。从2004年发布至今,凭借开源的力量,已经接近成熟与完善。
160 0
Nginx——详解
|
存储 缓存 安全
Nginx基本应用(一)
Nginx基本应用(一)
Nginx基本应用(一)