zoukankan      html  css  js  c++  java
  • 源码编译NGINX

    一、下载nginx
    [root@Alen ~]# cd /opt/ && ls
    [root@Alen /opt/]# wget http://nginx.org/download/nginx-1.16.1.tar.gz
    --2020-02-09 15:13:30--  http://nginx.org/download/nginx-1.16.1.tar.gz
    正在解析主机 nginx.org (nginx.org)... 62.210.92.35, 95.211.80.227, 2001:1af8:4060:a004:21::e3
    正在连接 nginx.org (nginx.org)|62.210.92.35|:80... 已连接。
    已发出 HTTP 请求,正在等待回应... 200 OK
    长度:1032630 (1008K) [application/octet-stream]
    正在保存至: “nginx-1.16.1.tar.gz”
    
    100%[=============================================================>] 1,032,630   2.78KB/s 用时 9m 23s 
    
    2020-02-09 15:22:54 (1.79 KB/s) - 已保存 “nginx-1.16.1.tar.gz” [1032630/1032630])
    [root@Alen opt]# ls
    nginx-1.16.1.tar.gz
    二、安装依赖包
    [root@Alen opt]# yum -y install gcc gcc-c++ make automake autoconf libtool pcre* zlib openssl openssl-devel
    ******
    
    完毕!
    三、解压
    [root@Alen opt]# tar -xzf nginx-1.16.1.tar.gz 
    [root@Alen opt]# ls
    nginx-1.16.1  nginx-1.16.1.tar.gz
    [root@Alen opt]# cd nginx-1.16.1/
    [root@Alen nginx-1.16.1]# ll
    总用量 756
    drwxr-xr-x. 6 1001 1001   4096 2月   9 15:28 auto    # 提供了4个子目录
    -rw-r--r--. 1 1001 1001 296463 8月  13 20:51 CHANGES    # 对nginx版本中有哪些特性和bugfix进行说明
    -rw-r--r--. 1 1001 1001 452171 8月  13 20:51 CHANGES.ru    # 俄罗斯语言版本的CHANGES
    drwxr-xr-x. 2 1001 1001   4096 2月   9 15:28 conf    # 示例文件,安装好之后会将此目录中的示例文件拷贝到安装目录以方便配置
    -rwxr-xr-x. 1 1001 1001   2502 8月  13 20:51 configure    # 用来生成中间文件,执行编译前的一个必备动作
    drwxr-xr-x. 4 1001 1001     68 2月   9 15:28 contrib    # 提供了两个pa脚本,和vim的工具
    drwxr-xr-x. 2 1001 1001     38 2月   9 15:28 html    # 提供了两个标准的html文件
    -rw-r--r--. 1 1001 1001   1397 8月  13 20:51 LICENSE    
    drwxr-xr-x. 2 1001 1001     20 2月   9 15:28 man    # Linux对nginx的帮助文件,这里可以看到nginx的基本帮助和配置
    -rw-r--r--. 1 1001 1001     49 8月  13 20:51 README
    drwxr-xr-x. 9 1001 1001     84 2月   9 15:28 src    # 框架都在此目录的代码中
    四、配置,使vim打开nginx配置文件时语法高亮
    [root@Alen nginx-1.16.1]# mkdir /root/.vim
    [root@Alen nginx-1.16.1]# cp -r contrib/vim/* /root/.vim/
    五、查看NGINX的html目录结构
    [root@Alen nginx-1.16.1]# tree html/
    html/
    ├── 50x.html    # 发生50X错误时,可以重定向到此文件
    └── index.html    # 默认的NGINX欢迎界面
    
    0 directories, 2 files
    六、查看configure支持哪些参数,使用more分页查看,空格翻页,q退出
    [root@Alen nginx-1.16.1]# ./configure --help | more
    七、配置:使用默认参数指定nginx的安装目录,配置成功后,nginx的配置特性以及nginx的执行木等信息都会列在最下方
    [root@Alen nginx-1.16.1]# mkdir /opt/nginx
    [root@Alen nginx-1.16.1]# ./configure --prefix=/opt/nginx
    八、执行完configure命令后nginx-1.16.1目录下会多出以下两个内容
    -rw-r--r-- 1 root root   356 2月 9 16:06 Makefile
    drwxr-xr-x 3 root root    174 2月 9 16:06 objs    # 生成的中间文件
    [root@Alen nginx-1.16.1]# cd objs/
    [root@Alen objs]# ll
    总用量 80
    -rw-r--r--. 1 root root 17628 2月 9 16:07 autoconf.err
    -rw-r--r--. 1 root root 39886 2月 9 16:07 Makefile
    -rw-r--r--. 1 root root 6791 2月 9 16:07 ngx_auto_config.h
    -rw-r--r--. 1 root root 657 2月 9 16:07 ngx_auto_headers.h
    -rw-r--r--. 1 root root 5856 2月 9 16:07 ngx_modules.c  # 决定了接下来编译时,有哪些模块会被编译进nginx
    drwxr-xr-x. 9 root root 84 2月 9 16:07 src  # C语言编译时生成的中间文件都会放在此目录
    九、编译
    [root@Alen objs]# cd ..
    [root@Alen nginx-1.16.1]# make
    # 编译完成后,objs目录下会生成大量中间文件,主要为以下三部分
    # 如果需要对nginx进行版本升级,则需要从objs中将nginx执行文件拷贝到nginx的安装目录中
    # 如果使用了动态模块,那么动态模块编译会生成so动态文件,届时也会放在objs目录下
    -rwxr-xr-x. 1 root root 3825645 2月 9 16:25 nginx
    -rw-r--r--. 1 root root 5317 2月 9 16:25 nginx.8
    -rw-r--r--. 1 root root 32312 2月 9 16:25 ngx_modules.o
    十、make install 安装,只有首次安装时可使用此命令
    # 安装完成后,前往prefix指定的目录可以看到以下结构
    [root@Alen nginx-1.16.1]# cd ../nginx
    [root@Alen nginx]# ll
    总用量 4
    drwxr-xr-x. 2 root root 4096 2月   9 16:42 conf  # 决定nginx功能的配置文件在conf下
    drwxr-xr-x. 2 root root   38 2月   9 16:42 html
    drwxr-xr-x. 2 root root    6 2月   9 16:42 logs  # access.log和error.log在logs下
    drwxr-xr-x. 2 root root   18 2月   9 16:42 sbin  # 最主要的nginx二进制文件在sbin下
  • 相关阅读:
    mysql数据库(12)--进阶二之索引
    mysql数据库(11)--进阶一之join
    mysql数据库(10)--变量、存储过程和函数
    mysql数据库(9)--视图
    mysql数据库(10)--limit与offset的用法
    前端常用在线引用地址
    SQL中ON和WHERE的区别
    jstl和e1
    解决中文乱码问题
    JSP
  • 原文地址:https://www.cnblogs.com/Axiao-47/p/12287700.html
Copyright © 2011-2022 走看看