源码安装nginx

安装nginx

  1. 下载包
    wget http://nginx.org/download/nginx-1.16.1.tar.gz
  2. 解压包
    tar xf nginx-1.16.1.tar.gz
    cd nginx-1.16.1
  3. 预编译
    ./configure
    
  • 预编译主要是用来检查系统环境是否满足安装软件包的条件, 并生成Makefile文件,该文件为编译、安装、升级nginx指明了相应参数。
    ./configure
  • –help 可以查看预编译参数
  • –prefix 指定nginx编译安装的目录;
  • –user=*** 指定nginx的属主 **
  • –group=* 指定nginx的属主与属组
  • –with-*** 指定编译某模块 **
  • –without- 指定不编译某模块
  • –add-module 编译第三方模块
  1. 若有报错,添加依赖
    checking for PCRE library ... not found
    checking for PCRE library in /usr/local/ ... not found
    checking for PCRE library in /usr/include/pcre/ ... not found
    checking for PCRE library in /usr/pkg/ ... not found
    checking for PCRE library in /opt/local/ ... not found
    
    ./configure: error: the HTTP rewrite module requires the PCRE library.
    You can either disable the module by using --without-http_rewrite_module
    option, or install the PCRE library into the system, or build the PCRE library
    statically from the source with nginx by using --with-pcre=<path> option.
    
    
    yum install gcc  gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y

​ 安装完依赖包后,重新编译并指定安装目录:

./configure --prefix=/usr/local/nginx
  1. 修改头文件,改变响应头信息中nginx的版本为,server : JFWS/1.1
    vim /nginx-1.16.1/src/core/nginx.h
    修改第13,14行
    #define NGINX_VERSION      "1.1"
    #define NGINX_VER          "JFWS/" NGINX_VERSION
    
  2. 编译并安装
    make && make install
    
  3. 查看版本并启动程序
    /usr/local/nginx/sbin/nginx -v
    nginx version: JFWS/1.1
    
    # 启动程序
    /usr/local/nginx/sbin/nginx
    
  4. 查看进程

    ps -ef|grep nginx
    
    root      11258      1  0 23:34 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/ngin
    nobody    11259  11258  0 23:34 ?        00:00:00 nginx: worker process
    root      11261   7360  0 23:35 pts/1    00:00:00 grep --color=auto nginx
    
    netstat -ntlp|grep 80
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11258/nginx: master
    
  5. 查看网页浏览器

在这里插入图片描述

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值