当前位置: 首页 > news >正文

Ubuntu服务器编译安装Nginx

Ubuntu服务器部署Nginx

1.切换到root权限

sudosu

2.安装依赖包

apt-getupdate# 更新下apt源apt-getinstall-ygccmakelibz-dev libpcre3-dev libssl-dev

3.进入下载目录,例如/usr/src/ (源码包下载目录)

cd/usr/src/

4.wget命令下载选择nginx版本的压缩包

wgethttp://nginx.org/download/nginx-1.26.2.tar.gz

5.tar解压

tar-zxvfnginx-1.26.2.tar.gz

6.进入解压的文件夹

cd/usr/src/nginx-1.26.2

7.编辑编译内容

./configure--prefix=/usr/local/nginx-1.26\# 指定 Nginx 的安装目录--with-http_ssl_module\# 启用 HTTPS 模块--with-http_stub_status_module\# 启用 Stub Status 模块--with-http_gzip_static_module\# 启用 Gzip 静态模块--with-stream\# 启用 Stream 模块--with-http_realip_module\# 启用 Real IP 模块--with-http_flv_module\# 启用 FLV 模块--with-http_random_index_module\# 启用 Random Index 模块--with-mail\# 启用 Mail 模块--with-pcre\# 启用 PCRE--user=nginx\# 指定 Nginx 用户--group=nginx\# 指定 Nginx 组--with-file-aio\# 启用文件异步 IO--with-http_rewrite_module\# 启用 Rewrite 模块(1.26以上版本的nginx不用加)

8.编译安装

make#执行编译,生成Makefilemakeinstall#编译安装

9.启动Nginx

cd/usr/local/nginx-1.26.2/sbin#进入执行文件目录./nginx#启动nginx

10.查看Nginx后台信息

ps-ef|grepnginx
返回以下信息↓
root13730051016:00 ? 00:00:00 nginx: master process ./nginx nobody13730061373005016:00 ? 00:00:00 nginx: worker process root13730271358582016:00 pts/6 00:00:00grep--color=auto nginx

11.测试连接

curl http://localhost
返回以下信息↓
<!DOCTYPEhtml><html><head><title>Welcome to nginx!</title><style>html{color-scheme:light dark;}body{width:35em;margin:0 auto;font-family:Tahoma,Verdana,Arial,sans-serif;}</style></head><body><h1>Welcome to nginx!</h1><p>If you see this page, the nginx web server is successfully installed and working. Further configuration is required.</p><p>For online documentation and support please refer to<ahref="http://nginx.org/">nginx.org</a>.<br/>Commercial support is available at<ahref="http://nginx.com/">nginx.com</a>.</p><p><em>Thank you for using nginx.</em></p></body></html>

12.Nginx服务的操作

./nginx #启动 ./nginx -s stop #关闭 ./nginx -s reload #重启

通过以上步骤,就完成了在Ubuntu系统下从源码成功安装并配置Nginx。

13.配置Systemctl控制nginx

创建一个名为nginx.service的文件,通常放在/etc/systemd/system/目录下

[Unit]Description=The NGINX HTTP and reverse proxy serverAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginx#启动nginx执行文件路径ExecReload=/usr/local/nginx/sbin/nginx-sreload#启动nginx执行文件路径ExecStop=/usr/local/nginx/sbin/nginx-squit#启动nginx执行文件路径PrivateTmp=true[Install]WantedBy=multi-user.target

设置开机自启动

# 启用 Nginx 服务,使其在系统启动时自动启动sudosystemctlenablenginx# 启动 Nginx 服务sudosystemctl start nginx# 检查 Nginx 服务的状态sudosystemctl status nginx# 停止 Nginx 服务sudosystemctl stop nginx# 禁用 Nginx 服务,使其不会在系统启动时自动启动sudosystemctl disable nginx
http://www.jsqmd.com/news/642218/

相关文章:

  • 生成对抗网络 GAN 基础:对抗训练原理
  • Vivado新手必看:Zynq开发板串口无打印的5个常见原因及解决方法
  • 电力电子变压器与磁学知识点梳理笔记
  • 手把手教你为vSAN集群规划网络:ESXi 8.0U3e多网卡、VLAN与IP地址实战配置
  • 从矩阵视角解析OTFS:输入输出关系的实现与演进
  • League Akari:英雄联盟智能辅助工具终极指南
  • 从RAG到自更新知识库
  • CTF入门指南:Web安全提权实战解析
  • Haystack实战指南:从零构建高效RAG应用
  • Knowledge - Based Systems、 Declaration of Interest statement 是什么? 爱思唯尔论文需要每个人同意吗
  • 我装了 30 多个 Claude Code Skill,每天真开的就 6 个
  • 光耦合器引脚识别指南:从基础到实战技巧
  • 5分钟终极指南:为Jellyfin安装maxsubtitle智能字幕插件
  • 专访翼程教育:从5省到21省的17年坚守——一家“慢”机构如何用合规与全托管穿越行业周期 - 商业科技观察
  • 断言基础:程序正确性校验核心用法
  • qutip——玩(1)
  • 避开IGBT炸管坑:从栅极电阻配置看开关损耗与EMI的平衡术
  • LCL型三相并网变流器输出阻抗建模与锁相环影响分析
  • Mixly二次开发实战:从零构建自定义make库模块
  • 【倒计时30天】SITS2026多模态推荐系统技术白皮书即将下线:含17个可复用损失函数设计与TensorRT加速模板
  • 2026年4月珠海家装公司推荐:五家口碑产品评测对比领先新房装修预算超支 - 品牌推荐
  • 2026年4月新消息:深度解析安徽崇贤人力在合肥人力资源市场的差异化服务价值 - 2026年企业推荐榜
  • 实战指南 | 基于华为海思Hi3861与鸿蒙系统的物联网创新项目开发全解析(附资源)
  • c语言的基础学习.pptx
  • 知识图谱技术应用全景:国内外领先企业解决方案解析
  • OpenClaw保姆级安装教程:基于ubuntu系统
  • UVM之sequencer
  • 从零到一:基于STM32F103RCT6与矩阵键盘的嵌入式系统双项目实战
  • 2026年4月更新:伺服热板塑料焊接技术演进与**生产商宁波威博深度聚焦 - 2026年企业推荐榜
  • 分析和存储日志知识点问答