CentOS8源码安装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 sbin
conf 放配置文件
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
[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 ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: 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 firewalld
1:查看防火状态
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
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 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
ror: SSL modules require the OpenSSL library.
//解决
[root@localhost nginx-1.20.2]# dnf -y install openssl openssl-devel