热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

源码安装Nginx解决报错

CentOS8源码安装Nginx编译安装注意事项如果安装时不是使用的默认路径,则必须要修改PATH环境变量,以能够识别此程序的二进制文件路径

CentOS8源码安装Nginx


编译安装注意事项


  • 如果安装时不是使用的默认路径,则必须要修改PATH环境变量,以能够识别此程序的二进制文件路径;
    • 修改/etc/profile文件或在/etc/profile.d/目录建立一个以.sh为后缀的文件,在里面定义export PATH=/path/to/somewhere:$PATH
  • 默认情况下,系统搜索库文件的路径只有/lib,/usr/lib
    • 增添额外库文件搜索路径方法:
      • 在/etc/ld.so.conf.d/中创建以.conf为后缀名的文件,而后把要增添的路径直接写至此文件中。此时库文件增添的搜索路径重启后有效,若要使用增添的路径立即生效则要使用ldconfig命令
    • ldconfig:通知系统重新搜索库文件

/etc/ld.so.conf和/etc/ls.so.conf.d/*.conf //配置文件
/etc/ld.so.cache //缓存文件
-v //显示重新搜索库的过程
-p //打印出系统启动时自动加载并缓存到内存中的可用库文件名及文件路径映射关系

  • 头文件:输出给系统
    • 默认:系统在/usr/include中找头文件,若要增添头文件搜索路径,使用链接进行
  • man文件路径:安装在–prefix指定的目录下的man目录
    • 默认:系统在/usr/share/man中找man文件。此时因为编译安装的时候不是安装到默认路径下,如果要查找man文件则可以使用以下两种方法:
      • man -M /path/to/man_dir command
      • 在/etc/man_db.conf文件中添加一条MANPATH

源码包编译实例

下面通过编译安装nginx来深入理解源码包安装

//1.下载Nginx
[root@localhost ~]# wget https://nginx.org/download/nginx-1.20.2.tar.gz //2.解压包
[root@localhost ~]# tar xf nginx-1.20.2.tar.gz
[root@localhost ~]# cd nginx-1.20.2//3.指定编译参数
[root@localhost nginx-1.20.2]# ./configure --prefix=/usr/local/nginx //4.验证这一步命令是否成功, 非0的都不算成功
[root@localhost nginx-1.20.2]# echo $?
0
//查看make命令是否存在,没有
[root@localhost nginx-1.20.2]# which make
/usr/bin/which: no make in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
//安装make命令
[root@localhost ~]# dnf -y install make
//查看cup核心数,使用只能低于核心数
[root@localhost ~]# nproc
4
//使用make编译必须在生成makefile的文件目录下使用若出现报错或安装失败需删除目录重新开始上述步骤
[root@localhost nginx-1.20.2]# make -j 3 [root@localhost nginx-1.20.2]# make install//查看Nginx里面有什么?
[root@localhost ~]# ls /usr/local/nginx
conf html logs sbinconf 放配置文件
html 放网站的
logs 放日志的
sbin 放程序文件的
//查看未发现80端口(ngxin端口80)
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:* //启动Nginx (这种方式启动nginx麻烦,设置环境变量直接nginx启动)
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*

//配置环境变量

//第一种方式配置环境变量
[root@localhost ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
[root@localhost ~]# cat /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH
//第二种方式配置环境变量 (vim写比较稳妥)
[root@localhost ~]# vim /etc/profile.d/nginx.sh
[root@localhost ~]# cat /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin:$PATH //写入nginx.sh文件里//刷新
[root@localhost ~]# source /etc/profile.d/nginx.sh
[root@localhost ~]# echo $PATH
/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin//杀掉nginx进程
[root@localhost ~]# pkill nginx//查看端口号
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:* //启动nginx
[root@localhost ~]# nginx
//查看端口号
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*

//假设配置头文件 (因为nginx没有头文件)

//有头文件就要做软连接
[root@localhost ~]# ln -s /usr/local/nginx/include /usr/include/nginx

//关闭防火墙再去访问

//查看防火墙状态(默认开机自启)
[root@localhost ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemonLoaded: loaded (/usr/lib/systemd/system/firewalld.service; enabl>Active: active (running) since Fri 2022-04-22 14:14:23 CST; 1h 5>Docs: man:firewalld(1)
//马上关掉防火墙(关闭开机自启)
[root@localhost ~]# systemctl disable --now firewalld1:查看防火状态
systemctl status firewalld
service iptables status
2:暂时关闭防火墙
systemctl stop firewalld
service iptables stop
3:永久关闭防火墙
systemctl disable firewalld
chkconfig iptables off
4:开启防火墙
systemctl enable firewalld
service iptables restart
5.:重启防火墙
systemctl restart firewalld

ip访问nginx (出现这个就OK了)

在这里插入图片描述


源码编译报错信息处理

//执行./configure --prefix=/usr/local/nginx报的错
./configure: error: C compiler cc is not found//解决
[root@localhost nginx-1.20.2]# dnf -y install gcc gcc-c++//执行dnf -y install gcc gcc-c++报的错
Error: Problem: package gcc-8.5.0-4.el8_5.x86_64 requires glibc-devel >= 2.2.90-12, but none of the providers can be installed//解决
[root@localhost nginx-1.20.2]# dnf -y install boost-devel --allowerasing//执行./configure --prefix=/usr/local/nginx报的错
./configure: error: the HTTP rewrite module requires the PCRE library.//解决
[root@localhost nginx-1.20.2]# dnf -y install pcre-devel//执行./configure --prefix=/usr/local/nginx报的错
./configure: error: the HTTP gzip module requires the zlib library.//解决
[root@localhost nginx-1.20.2]# dnf -y install zlib-devel//问题?(使用https证书需要这个库开启),现在只管安装
Configuration summary+ using system PCRE library+ OpenSSL library is not used //没有使用到系统OpenSSL库+ using system zlib library//查看系统OpenSSL库,默认是关闭的
[root@localhost nginx-1.20.2]# ./configure --help|grep ssl--with-http_ssl_module enable ngx_http_ssl_module//启动它就解决了
[root@localhost nginx-1.20.2]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module //执行./configure --prefix=/usr/local/nginx --with-http_ssl_module 报的错
./configure: error: SSL modules require the OpenSSL library.//解决
[root@localhost nginx-1.20.2]# dnf -y install openssl openssl-devel

推荐阅读
  • 阿里云ecs怎么配置php环境,阿里云ecs配置选择 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • 360SRC安全应急响应:从漏洞提交到修复的全过程
    本文详细介绍了360SRC平台处理一起关键安全事件的过程,涵盖从漏洞提交、验证、排查到最终修复的各个环节。通过这一案例,展示了360在安全应急响应方面的专业能力和严谨态度。 ... [详细]
  • 本文详细介绍了macOS系统的核心组件,包括如何管理其安全特性——系统完整性保护(SIP),并探讨了不同版本的更新亮点。对于使用macOS系统的用户来说,了解这些信息有助于更好地管理和优化系统性能。 ... [详细]
  • 使用Vultr云服务器和Namesilo域名搭建个人网站
    本文详细介绍了如何通过Vultr云服务器和Namesilo域名搭建一个功能齐全的个人网站,包括购买、配置服务器以及绑定域名的具体步骤。文章还提供了详细的命令行操作指南,帮助读者顺利完成建站过程。 ... [详细]
  • 在当前众多持久层框架中,MyBatis(前身为iBatis)凭借其轻量级、易用性和对SQL的直接支持,成为许多开发者的首选。本文将详细探讨MyBatis的核心概念、设计理念及其优势。 ... [详细]
  • 从 .NET 转 Java 的自学之路:IO 流基础篇
    本文详细介绍了 Java 中的 IO 流,包括字节流和字符流的基本概念及其操作方式。探讨了如何处理不同类型的文件数据,并结合编码机制确保字符数据的正确读写。同时,文中还涵盖了装饰设计模式的应用,以及多种常见的 IO 操作实例。 ... [详细]
  • 网络运维工程师负责确保企业IT基础设施的稳定运行,保障业务连续性和数据安全。他们需要具备多种技能,包括搭建和维护网络环境、监控系统性能、处理突发事件等。本文将探讨网络运维工程师的职业前景及其平均薪酬水平。 ... [详细]
  • PHP 5.5.0rc1 发布:深入解析 Zend OPcache
    2013年5月9日,PHP官方发布了PHP 5.5.0rc1和PHP 5.4.15正式版,这两个版本均支持64位环境。本文将详细介绍Zend OPcache的功能及其在Windows环境下的配置与测试。 ... [详细]
  • 本文详细记录了在银河麒麟操作系统和龙芯架构上使用 Qt 5.15.2 进行项目打包时遇到的问题及解决方案,特别关注于 linuxdeployqt 工具的应用。 ... [详细]
  • 本文详细介绍了MicroATX(也称Mini ATX)和MATX主板规格,探讨了它们的结构特点、应用场景及对电脑系统成本和性能的影响。同时,文章还涵盖了相关操作系统的实用技巧,如蓝牙设备图标删除、磁盘管理等。 ... [详细]
  • 在Python开发过程中,随着项目数量的增加,不同项目依赖于不同版本的库,容易引发依赖冲突。为了避免这些问题,并保持开发环境的整洁,可以使用Virtualenv和Virtualenvwrapper来创建和管理多个隔离的Python虚拟环境。 ... [详细]
  • 本文深入探讨了 Redis 的两种持久化方式——RDB 快照和 AOF 日志。详细介绍了它们的工作原理、配置方法以及各自的优缺点,帮助读者根据具体需求选择合适的持久化方案。 ... [详细]
  • 在成功安装和测试MySQL及Apache之后,接下来的步骤是安装PHP。为了确保安全性和配置的一致性,建议在安装PHP前先停止MySQL和Apache服务,并将MySQL集成到PHP中。 ... [详细]
  • 本文详细介绍了如何在预装Ubuntu系统的笔记本电脑上安装Windows 7。针对没有光驱的情况,提供了通过USB安装的具体方法,并解决了分区、驱动器无法识别等问题。 ... [详细]
author-avatar
Sunshine丶米粉_499
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有