nginx 的编译安装

一 系统环境

[demo@kk-0 ~]$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core) 

二 下载nginx安装文件
nginx: download

image.png

三 上传安装包到服务器
image.png

四 解压缩

[demo@kk-0 ~]$ tar -xvf nginx-1.20.1.tar.gz 
nginx-1.20.1/
nginx-1.20.1/auto/
nginx-1.20.1/conf/
nginx-1.20.1/contrib/
nginx-1.20.1/src/
nginx-1.20.1/configure
nginx-1.20.1/LICENSE
nginx-1.20.1/README
... ...

五 进入解压后的目录


image.png
[demo@kk-0 ~]$ cd nginx-1.20.1
[demo@kk-0 nginx-1.20.1]$ ls
auto  CHANGES  CHANGES.ru  conf  configure  contrib  html  LICENSE  man  README  src
[demo@kk-0 nginx-1.20.1]$ pwd
/home/demo/nginx-1.20.1

六 安装依赖

[demo@kk-0 nginx-1.20.1]$ sudo yum install zlib zlib-devel openssl openssl-devel gcc libpcre -y

七 配置编译参数

[demo@kk-0 nginx-1.20.1]$ sudo ./configure --prefix=/opt/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module
checking for OS
 + Linux 3.10.0-957.el7.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) 
... ...
... ...
checking for PCRE JIT support ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + using system OpenSSL library
  + using system zlib library

  nginx path prefix: "/opt/nginx"
  nginx binary file: "/opt/nginx/sbin/nginx"
  nginx modules path: "/opt/nginx/modules"
  nginx configuration prefix: "/opt/nginx/conf"
  nginx configuration file: "/opt/nginx/conf/nginx.conf"
  nginx pid file: "/opt/nginx/logs/nginx.pid"
  nginx error log file: "/opt/nginx/logs/error.log"
  nginx http access log file: "/opt/nginx/logs/access.log"
  nginx http client request body temporary files: "client_body_temp"
  nginx http proxy temporary files: "proxy_temp"
  nginx http fastcgi temporary files: "fastcgi_temp"
  nginx http uwsgi temporary files: "uwsgi_temp"
  nginx http scgi temporary files: "scgi_temp"

八 编译

[demo@kk-0 nginx-1.20.1]$ sudo make
make -f objs/Makefile
make[1]: Entering directory `/home/demo/nginx-1.20.1'
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/src/core/nginx.o \
    src/core/nginx.c
cc -c -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g  -I src/core -I src/event -I src/event/modules -I src/os/unix -I objs \
    -o objs/src/core/ngx_log.o \
    src/core/ngx_log.c
... ...
... ...
objs/src/http/modules/ngx_http_stub_status_module.o \
objs/ngx_modules.o \
-ldl -lpthread -lcrypt -lpcre -lssl -lcrypto -ldl -lpthread -lz \
-Wl,-E
sed -e "s|%%PREFIX%%|/opt/nginx|" \
    -e "s|%%PID_PATH%%|/opt/nginx/logs/nginx.pid|" \
    -e "s|%%CONF_PATH%%|/opt/nginx/conf/nginx.conf|" \
    -e "s|%%ERROR_LOG_PATH%%|/opt/nginx/logs/error.log|" \
    < man/nginx.8 > objs/nginx.8
make[1]: Leaving directory `/home/demo/nginx-1.20.1'

九 安装

[demo@kk-0 nginx-1.20.1]$ sudo make install
make -f objs/Makefile install
make[1]: Entering directory `/home/demo/nginx-1.20.1'
test -d '/opt/nginx' || mkdir -p '/opt/nginx'
test -d '/opt/nginx/sbin' \
    || mkdir -p '/opt/nginx/sbin'
... ...
... ...
    || mkdir -p '/opt/nginx/logs'
test -d '/opt/nginx/html' \
    || cp -R html '/opt/nginx'
test -d '/opt/nginx/logs' \
    || mkdir -p '/opt/nginx/logs'
make[1]: Leaving directory `/home/demo/nginx-1.20.1'

十 启动nginx测试

[demo@kk-0 nginx-1.20.1]$ sudo /opt/nginx/sbin/nginx -p /opt/nginx
[demo@kk-0 nginx-1.20.1]$ ps -ef |grep nginx
root      71863      1  0 14:21 ?        00:00:00 nginx: master process /opt/nginx/sbin/nginx -p /opt/nginx
nobody    71864  71863  0 14:21 ?        00:00:00 nginx: worker process
demo      71987  13721  0 14:21 pts/1    00:00:00 grep --color=auto nginx
image.png

你可能感兴趣的:(nginx 的编译安装)