依次执行
1.解压tar -zxvf xxx(nginx tar包)(命令安装wget https://nginx.org/download/nginx-1.21.6.tar.gz)
2. ./configure
3../configure --with-http_ssl_module --with-http_v2_module
或者
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-openssl=/opt/openssl-3.3.1
--prefix=/usr/local/nginx:这个选项设置了 Nginx 的安装前缀,即软件安装的基本目录。在这个例子中,Nginx 会被安装在/usr/local/nginx目录下。这里的文件结构会包括sbin、conf、logs等子目录。--with-http_stub_status_module:这个选项启用了 HTTP stub status 模块。这个模块提供了一个接口,可以返回 Nginx 的一些基本运行状态信息,如连接数、请求处理数等。这对于监控 Nginx 的性能非常有用。--with-http_ssl_module:这个选项启用了 HTTP SSL 模块,允许 Nginx 通过 HTTPS 提供安全的网页服务。这通常用于提供加密的网页内容,保护用户数据。
4.make
5.make install
6.vi
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存:wq /usr/lib/systemd/system/nginx.service
7.开放端口
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --zone=public --add-port=443/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
执行firewall-cmd --zone=public --add-port=80/tcp --permanent报错
原因 防火墙没开启
firewall-cmd --state; //查看自己防火墙的状态
systemctl start firewalld.service; //开启防火墙
8.服务命令
// 查看 nginx 状态
systemctl status nginx.service
// 启动 nginx
systemctl start nginx.service
// 停止 nginx
systemctl stop nginx.service
// 重启 nginx
systemctl restart nginx.service
// 开机自启
systemctl enable nginx.service
// 关闭开机自启
systemctl disable nginx.service
遇到的一些报错及解决命令 搬运文档
// 异常
/bin/sh: cc: command not found
// 解决 (缺少 gcc 包)
yum -y install gcc
// 异常
#include <openssl/ssl.h>
// 解决 (缺少 openssl 包)
yum -y install openssl-devel
// 异常
configure: error: *** zlib.h missing - please install first or check config.log ***
// 解决 (缺少 zlib 包)
yum -y install zlib-devel
总结: 遇到 # include <xxx.h>时,什么都不用考虑,直接取执行安装命令:yum -y install xxx-devel,然后进行重试