学习笔记:记录Linux编译安装nginx过程

以下记录CentOS7、openEuler2203、UOS V20 1050d编译安装nginx 1.24.0的全过程,包括一些依赖包的安装

一、下载nginx

$ sudo yum install wget #安装wget工具

$ wget http://nginx.org/download/nginx-1.24.0.tar.gz #下载nginx

二、解包

$ tar -xf nginx-1.24.0.tar.gz
-bash: tar:未找到命令

$ sudo yum install tar #安装tar工具

$ tar -xf nginx-1.24.0.tar.gz #解包nginx

三、配置

$ cd nginx-1.24.0

$ ./configure #第一次报错缺少cc编译工具
checking for OS
 + Linux 5.10.0-136.12.0.86.oe2203sp1.x86_64 x86_64
checking for C compiler ... not found

./configure: error: C compiler cc is not found

$ sudo yum install gcc-c++ #安装编译器 Debian中sudo apt install gcc

$ ./configure #第二次报错缺少PCRE库
......
./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.


$ sudo yum install pcre-devel #安装pcre开发包 Debian中sudo apt install libpcre3-dev


$ ./configure #第三次报错缺少zlib库
......
./configure: error: the HTTP gzip module requires the zlib library.
You can either disable the module by using --without-http_gzip_module
option, or install the zlib library into the system, or build the zlib library
statically from the source with nginx by using --with-zlib=<path> option.


$ sudo yum install zlib-devel #安装zlib开发包 Debian中sudo apt install zlib1g-dev

$ ./configure #第四次报告没有用OpenSSL库
......
checking for getaddrinfo() ... found
checking for PCRE2 library ... not found
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for zlib library ... found
creating objs/Makefile

Configuration summary
  + using system PCRE library
  + OpenSSL library is not used      <<<<<< 注意这里
  + using system zlib library

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/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"


$ ./configure --help | grep ssl #通过帮助信息查看什么参数可以支持用OpenSSL
  --with-http_ssl_module             enable ngx_http_ssl_module        <<<<<<就是这条
  --with-mail_ssl_module             enable ngx_mail_ssl_module
  --with-stream_ssl_module           enable ngx_stream_ssl_module
  --with-stream_ssl_preread_module   enable ngx_stream_ssl_preread_module
  --with-openssl=DIR                 set path to OpenSSL library sources
  --with-openssl-opt=OPTIONS         set additional build options for OpenSSL

$ ./configure --with-http_ssl_module #配置含http ssl module编译,第五次报错缺少OpenSSL......
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.

$ sudo yum install openssl-devel #安装openssl开发包 Debian中sudo apt install libssl-dev

$ ./configure --with-http_ssl_module #第六次成功
checking for OS
 + Linux 5.10.0-136.12.0.86.oe2203sp1.x86_64 x86_64
checking for C compiler ... found
 + using GNU C compiler
 + gcc version: 10.3.1 (GCC)
checking for gcc -pipe switch ... found
checking for -Wl,-E switch ... found
......
checking for openat(), fstatat() ... found
checking for getaddrinfo() ... found
checking for PCRE2 library ... found
checking for OpenSSL library ... found
checking for zlib library ... found
creating objs/Makefile

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

  nginx path prefix: "/usr/local/nginx"
  nginx binary file: "/usr/local/nginx/sbin/nginx"
  nginx modules path: "/usr/local/nginx/modules"
  nginx configuration prefix: "/usr/local/nginx/conf"
  nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  nginx error log file: "/usr/local/nginx/logs/error.log"
  nginx http access log file: "/usr/local/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"

四、编译

$ make
-bash: make:未找到命令

$ sudo yum install make #安装make命令

$ make

五、安装

$ sudo make install

六、测试

$ /usr/local/nginx/sbin/nginx -v #查看nginx版本,看到版本信息说明安装成功了
nginx version: nginx/1.24.0

$ sudo yum install net-tools #安装网络工具包(含netstat)

$ netstat -tunple #查看端口状态

$ sudo /usr/local/nginx/sbin/nginx #启动nginx

$ sudo vi /usr/local/nginx/conf/nginx.conf #编辑配置文件

$ sudo /usr/local/nginx/sbin/nginx -t #检查配置文件

$ sudo /usr/local/nginx/sbin/nginx -s reload #重新加载配置文件

$ systemctl status firewalld #查看防火墙状态 注意:Debian的防火墙可能是iptables

$ sudo firewall-cmd --list-all #查看防火墙配置

$ sudo firewall-cmd --add-port 80/tcp --permanent #永久开放80/tcp端口(重新加载后生效)

$ sudo firewall-cmd --reload #重新加载防火墙配置(永久设置必需在重新加载后生效)

七、几个Debian安装软件包的相关命令记录

$ apt depends net-tools #查看net-tools软件包的依赖包
$ apt download net-tools #下载net-tools软件包的deb文件,不安装
$ dpkg -i net-tools_1.60+git20180626.aebd88e-1_amd64.deb #安装deb文件的软件包
  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值