【推荐 - 源码安装】nginx - 安装
准备
- 查看操作系统的版本信息
[root@lab10 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
- 查看操作系统的网卡地址
[root@lab10 ~]# ip address show ens32
2: ens32: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:ec:f2:1b brd ff:ff:ff:ff:ff:ff
inet 10.1.1.10/24 brd 10.1.1.255 scope global ens32
valid_lft forever preferred_lft forever
inet6 fe80::20c:29ff:feec:f21b/64 scope link
valid_lft forever preferred_lft forever
创建nginx的源码目录
mkdir -p /opt/nginx
下载
- 访问https://nginx.org/en/download.html,下载 nginx
下载链接:https://nginx.org/download/nginx-1.26.2.tar.gz
文件全称:nginx-1.26.2.tar.gz
文件md5:1588676BE2A01A63D3A150FAE6C3F4A9
上传
将上述 下载
的5个安装包上传至 /opt/nginx
安装编译环境
yum -y install make gcc pcre-devel openssl-devel zlib-devel perl-ExtUtils-Embed
创建 nginx
用户
useradd -s /sbin/nologin -r nginx
进入nginx源码目录
cd /opt/nginx
解压
tar -zxvf nginx-1.26.2.tar.gz
进入解压目录
cd /opt/nginx/nginx-1.26.2
执行配置
./configure \
--user=nginx \
--group=nginx \
--with-stream \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream_ssl_module \
--with-stream_realip_module \
--with-file-aio
编译
make
安装
make install
添加脚本
echo "/usr/local/nginx/sbin:${PATH}" > /etc/profile.d/nginx.sh
配置服务
vim /lib/systemd/system/nginx.service
内容如下:
[Unit]
Description=The nginx HTTP and reverse proxy server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
PidFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s hup $mainpid
ExecStop=/bin/kill -s quit $mainpid
PrivateTmp=true
[Install]
WantedBy=multi-user.target
重载
systemctl daemon-reload
设置自动启动与启动nginx服务
systemctl enable --now nginx
访问
浏览器访问 https://10.1.1.10 ,效果如下
参考链接:
好好学习,天天向上。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」