Nginx的源码编译

Nginx的源码编译

这个实验的核心是从源码编译安装 Nginx并配置系统服务,相比直接用yum/dnf安装预编译包,源码编译能更灵活地定制 Nginx 功能

1.下载软件

复制代码
[root@Nginx ~]# wget https://nginx.org/download/nginx-1.28.1.tar.gz

2.解压

复制代码
[root@Nginx ~]# tar zxf nginx-1.28.1.tar.gz
[root@Nginx ~]# cd nginx-1.28.1/
[root@Nginx nginx-1.28.1]# ls
auto     CHANGES.ru          conf       contrib          html     man        SECURITY.md
CHANGES  CODE_OF_CONDUCT.md  configure  CONTRIBUTING.md  LICENSE  README.md  src

3.检测环境

复制代码
#安装依赖性
[root@Nginx ~]# dnf install gcc openssl-devel.x86_64 pcre2-devel.x86_64 zlib-devel -y

[root@Nginx nginx-1.28.1]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --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 --with-stream_ssl_module --with-stream_realip_module

4.编译

复制代码
[root@Nginx nginx-1.28.1]# make
[root@Nginx nginx-1.28.1]# make install

5.nginx启动

复制代码
#设定环境变量
[root@Nginx sbin]# vim  ~/.bash_profile
export PATH=$PATH:/usr/local/nginx/sbin

[root@Nginx sbin]# source   ~/.bash_profile


[root@Nginx logs]# useradd  -s /sbin/nologin -M nginx
[root@Nginx logs]# nginx
[root@Nginx logs]# ps aux | grep nginx
root       44012  0.0  0.1  14688  2356 ?        Ss   17:01   0:00 nginx: master process nginx
nginx      44013  0.0  0.2  14888  3892 ?        S    17:01   0:00 nginx: worker process
root       44015  0.0  0.1   6636  2176 pts/0    S+   17:01   0:00 grep --color=auto nginx


#测试
[root@Nginx logs]# echo timinglee > /usr/local/nginx/html/index.html

[root@Nginx logs]# curl  172.25.254.100
timinglee

6.编写启动文件

复制代码
[root@Nginx ~]# vim /usr/lib/systemd/system/nginx.service
[Unit]
Description=The NGINX HTTP and reverse proxy server
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

[root@Nginx ~]# systemctl daemon-reload

#验证
[root@Nginx ~]# systemctl status nginx.service
○ nginx.service - The NGINX HTTP and reverse proxy server
     Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; preset: disabled)
     Active: inactive (dead)

[root@Nginx ~]# systemctl enable --now nginx
[root@Nginx ~]# ps aux | grep nginx
root        1839  0.0  0.1  14688  2356 ?        Ss   09:53   0:00 nginx: master process /usr/local/nginx/sbin/nginx
nginx       1840  0.0  0.2  14888  3828 ?        S    09:53   0:00 nginx: worker process

[root@Nginx ~]# reboot
[root@Nginx ~]# systemctl status nginx.service
相关推荐
zhz521414 小时前
服务器等保加固实施报告
运维·服务器·信创·国密·等保
s_w.h16 小时前
【 linux 】文件系统
linux·运维·服务器·算法·bash
duoduo_sing16 小时前
数据库备份终极方案:从脚本手动到自动化热备+异地同步实战
运维·数据库·自动化·用友
风曦Kisaki16 小时前
# Linux运维Day06:HAproxy负载均衡(代理调度软件对比)、Tomcat服务部署与LNMJ架构
linux·运维·负载均衡
Albert Edison17 小时前
【Docker】Ubuntu22.04 安装 Docker 教程
运维·docker·容器
五阿哥永琪17 小时前
Nginx入门教学+实战
运维·nginx
小快说网安17 小时前
云服务器抗 DDoS 只靠基础防护够吗?
运维·服务器·ddos
怎么没有名字注册了啊17 小时前
fedora 换源教程
linux·运维·服务器
codefan※17 小时前
一键部署私人 LLM:Ollama + Docker 极简指南
运维·docker·容器·大模型·llm·本地部署·ollama