安装nginx

安装nginx

安装nginx有两种方法:

  • 一、共在centos下使用yum或者是deepin下使用apt-get这种系统自带的工具进行下载安装nginx

  • 二、下载nginx包进行编译安装nginx

因为nginx的官方模块并不是每一个都默认开启的,如果你只想添加第三方的nginx模块,必须通过编译安装这样的方式才能把第三方这种强大的生态圈的功能添加到我们的nginx中

编译安装nginx主要分为一下6个部分

(1)下载Nginx (2)介绍各种目录 (3)Configure (4)中间件介绍 (5)编译 (6)安装

  • 第一步下载nginx这里我们使用wget命令下载
wget http://nginx.org/download/nginx-1.16.1.tar.gz
  • 然后我们解压文件并且进入nginx包体内
tar -xfz nginx-1.16.1.tar.gz
cd nginx-1.16.1.tar.gz
[root@localhost nginx-1.16.1]# ll
总用量 748
drwxr-xr-x 6 1001 1001    326 4月  12 17:08 auto
-rw-r--r-- 1 1001 1001 296463 8月  13 2019 CHANGES
-rw-r--r-- 1 1001 1001 452171 8月  13 2019 CHANGES.ru
drwxr-xr-x 2 1001 1001    168 4月  12 17:08 conf
-rwxr-xr-x 1 1001 1001   2502 8月  13 2019 configure
drwxr-xr-x 4 1001 1001     72 4月  12 17:08 contrib
drwxr-xr-x 2 1001 1001     40 4月  12 17:44 html
-rw-r--r-- 1 1001 1001   1397 8月  13 2019 LICENSE
drwxr-xr-x 2 1001 1001     21 4月  12 17:48 man
-rw-r--r-- 1 1001 1001     49 8月  13 2019 README
drwxr-xr-x 9 1001 1001     91 4月  12 17:08 src

一、让我们看看第一个目录auto

[root@localhost nginx-1.16.1]# cd auto/
[root@localhost auto]# ll
总用量 188
drwxr-xr-x  2 1001 1001   133 4月  12 17:08 cc
-rw-r--r--  1 1001 1001   141 8月  13 2019 define
-rw-r--r--  1 1001 1001   889 8月  13 2019 endianness
-rw-r--r--  1 1001 1001  2812 8月  13 2019 feature
-rw-r--r--  1 1001 1001   136 8月  13 2019 have
-rw-r--r--  1 1001 1001   137 8月  13 2019 have_headers
-rw-r--r--  1 1001 1001   411 8月  13 2019 headers
-rw-r--r--  1 1001 1001  1020 8月  13 2019 include
-rw-r--r--  1 1001 1001   745 8月  13 2019 init
-rw-r--r--  1 1001 1001  4836 8月  13 2019 install
drwxr-xr-x 11 1001 1001   163 4月  12 17:08 lib
-rw-r--r--  1 1001 1001 18264 8月  13 2019 make
-rw-r--r--  1 1001 1001  3183 8月  13 2019 module
-rw-r--r--  1 1001 1001 38490 8月  13 2019 modules
-rw-r--r--  1 1001 1001   136 8月  13 2019 nohave
-rw-r--r--  1 1001 1001 25295 8月  13 2019 options
drwxr-xr-x  2 1001 1001    88 4月  12 17:08 os
-rw-r--r--  1 1001 1001  8752 8月  13 2019 sources
-rw-r--r--  1 1001 1001   120 8月  13 2019 stubs
-rw-r--r--  1 1001 1001  2014 8月  13 2019 summary
-rw-r--r--  1 1001 1001   394 8月  13 2019 threads
drwxr-xr-x  2 1001 1001    65 4月  12 17:08 types
-rw-r--r--  1 1001 1001 26859 8月  13 2019 unix

  • auto目录中像cc他是用来编译的 os目录是对操作系统做判断的其他文件都是辅助configure脚本执行的时候判定我们的nginx支持哪些模块当前操作系统拥有哪些特性可以供nginx所使用

二、CHANGES文件

  • CHANGES文件就是nginx每个版本中提供了哪些特性
  • 因为作者是俄罗斯人所有CHANGES.ru就是他的俄语版本

我们简单浏览一下

Changes with nginx 1.16.1                                        13 Aug 2019
    *) Security: when using HTTP/2 a client might cause excessive memory
       consumption and CPU usage (CVE-2019-9511, CVE-2019-9513,
       CVE-2019-9516).
Changes with nginx 1.16.0                                        23 Apr 2019
    *) 1.16.x stable branch.
Changes with nginx 1.15.12                                       16 Apr 2019
    *) Bugfix: a segmentation fault might occur in a worker process if
       variables were used in the "ssl_certificate" or "ssl_certificate_key"
       directives and OCSP stapling was enabled.
Changes with nginx 1.15.11                                       09 Apr 2019
    *) Bugfix: in the "ssl_stapling_file" directive on Windows.
Changes with nginx 1.15.10  

三、conf目录

  • conf是一个示例文件目录就是当我们把nginx安装好以后,方便运维人员去配置,会把conf示例文件拷贝到文件目录

四、configure

  • configure脚本是一个用来生成中间文件和执行编译前的必备动作

五、contrib

  • contrib目录这个目录他提供了俩个perl脚本和vim的工具,比如我们在没有使用这个工具打开nginx配置文件里面是没有颜色的

  • 想让我们的nginx的配置文件拥有色彩我们需要把contrib下的vim中的所有文件拷贝到我们的 /root/.vim/目录下如果没有.vim目录自己建一个

    cp -r /root/nginx-1.16.1/contrib/vim/* /root/.vim
    

六、html

  • html文件夹中提供了两个标准的html文件一个是默认的index.html首页文件一个是50X的状态码文件

七、man

  • man文件夹中是nginx的一些帮助文档
[root@localhost man]# man ./nginx.8
NGINX(8)                      BSD System Manager's Manual                      NGINX(8)
NAME
     nginx — HTTP and reverse proxy server, mail proxy server
SYNOPSIS
     nginx [-?hqTtVv] [-c file] [-g directives] [-p prefix] [-s signal]
DESCRIPTION
     nginx (pronounced “engine x”) is an HTTP and reverse proxy server, as well as a
     mail proxy server.  It is known for its high performance, stability, rich feature
     set, simple configuration, and low resource consumption.
     The options are as follows:
     -?, -h         Print help.
     -c file        Use an alternative configuration file.
     -g directives  Set global configuration directives.  See EXAMPLES for details.
     -p prefix      Set the prefix path.  The default value is %%PREFIX%%.
     -q             Suppress non-error messages during configuration testing.
     -s signal      Send a signal to the master process.  The argument signal can be

八、src

  • src目录中是nginx的源代码nginx的框架都在这里
[root@localhost src]# ll
总用量 20
drwxr-xr-x 2 1001 1001 4096 4月  12 17:08 core
drwxr-xr-x 3 1001 1001 4096 4月  12 17:08 event
drwxr-xr-x 4 1001 1001 4096 4月  12 17:08 http
drwxr-xr-x 2 1001 1001 4096 4月  12 17:08 mail
drwxr-xr-x 2 1001 1001   74 4月  12 17:08 misc
drwxr-xr-x 3 1001 1001   18 4月  12 17:08 os
drwxr-xr-x 2 1001 1001 4096 8月  13 2019 stream```

编译前我们看看configure都有哪些选项

./configure --help | more
--prefix=PATH                      set installation prefix
# 这个选项的作用是选择安装的位置
--with-select_module               enable select module
#这些需要加--with选项的模块默认不编译进nginx中如果需要使用得手动添加
--without-poll_module              disable poll module
#这些--without的模块是默认安装的如果不需要可以手动不添加

正式安装nginx

1.安装nginx的依赖

[root@nginx_server ~]# yum install -y gcc openssl-devel zlib-devel pcre-devel

2.运行configure

./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --http-client-body-temp-path=/var/tmp/nginx/client/ --http-proxy-temp-path=/var/tmp/nginx/proxy/ --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi/ --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi/ --http-scgi-temp-path=/var/tmp/nginx/scgi/ --with-pcre --with-file-aio --with-http_secure_link_module --with-threads

3.如果没有报错那么我们就可以进行编译和安装了

[root@nginx_server nginx-1.16.1]# make && make instal

如何开启nginx呢 我们可以这样

#开启nginx
/usr/local/nginx/sbin/nginx
#重写加载配置文件
/usr/local/nginx/sbin/nginx -s reload
#停止服务 
/usr/local/nginx/sbin/nginx -s stop
#查看nginx版本
/usr/local/nginx/sbin/nginx -v
posted @ 2020-07-09 00:08  秃维  阅读(182)  评论(0)    收藏  举报