ubuntu安装nginx最新稳定版 1.30.3 从源码编译安装可以自定义编译参数或添加第三方模块灵活性高。1. 安装编译依赖sudo apt update sudo apt install build-essential libpcre3-dev zlib1g-dev libssl-dev -y # ubuntu26.04如果找不到libpcre3-dev # 下载 PCRE 源码 cd /usr/local/src # 下载地址1 sudo wget https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.gz sudo tar -xzf pcre-8.45.tar.gz # 下载地址2如果地址1不可用请尝试地址2 sudo wget http://mirror.dotsrc.org/tinycorelinux/14.x/x86_64/tcz/src/pcre/pcre-8.45.tar.bz2 tar -jxvf pcre-8.45.tar.bz22. 下载并解压源码cd /usr/local sudo wget https://nginx.org/download/nginx-1.30.3.tar.gz sudo tar -zxvf nginx-1.30.3.tar.gz cd nginx-1.30.33. 配置、编译与安装# 配置编译选项 sudo ./configure \ --prefix/usr/local/nginx \ --userwww \ --groupwww \ --with-http_ssl_module \ --with-http_stub_status_module # 如果找不到libpcre3-dev使用以下配置 ./configure --prefix/usr/local/nginx \ --userwww \ --groupwww \ --with-http_ssl_module \ --with-http_stub_status_module \ --with-pcre/usr/local/src/pcre-8.45 # 编译并安装 sudo make sudo make install4. 管理Nginx服务# 创建www用户 sudo adduser --system --group www # 赋予www用户可写权限 chown www:www /usr/local/nginx/logs/ # 启动Nginx sudo /usr/local/nginx/sbin/nginx # 重载配置 sudo /usr/local/nginx/sbin/nginx -s reload # 停止Nginx sudo /usr/local/nginx/sbin/nginx -s stop5.启动后通过浏览器或curl访问测试页面curl -I http://localhost后续配置1.配置防火墙如果启用了ufw需要放行 HTTP 和 HTTPS 流量。# 开放80 HTTP sudo ufw allow 80/tcp # 开放443 HTTPS sudo ufw allow 443/tcp # 或 sudo ufw allow http sudo ufw allow https2.设置开机自启a. 创建服务文件/etc/systemd/system/nginx.service。b. 写入以下内容[Unit] DescriptionThe NGINX HTTP and reverse proxy server Afternetwork.target remote-fs.target nss-lookup.target [Service] Typeforking PIDFile/usr/local/nginx/logs/nginx.pid ExecStartPre/usr/local/nginx/sbin/nginx -t ExecStart/usr/local/nginx/sbin/nginx ExecReload/usr/local/nginx/sbin/nginx -s reload ExecStop/usr/local/nginx/sbin/nginx -s stop PrivateTmptrue #Nginx在异常退出后自动重启 Restarton-failure RestartSec5 [Install] WantedBymulti-user.targetc. 重新加载 systemd 配置sudo systemctl daemon-reloadd.测试启动与配置检查# 检查配置语法systemd 的 ExecStartPre 也会做但手动验证更安心 sudo /usr/local/nginx/sbin/nginx -t # 使用 systemctl 启动 Nginx sudo systemctl start nginx # 如果启动失败可以通过以下命令查看详细错误 sudo systemctl status nginx # 查看服务状态和错误信息 sudo journalctl -u nginx -f # 实时查看 Nginx 的 systemd 日志e.设置开机自启# 确认服务能正常启动后启用开机自启 sudo systemctl enable nginxf.排错小贴士PID 文件路径不匹配如果 Nginx 的nginx.conf中使用了不同的 PID 文件路径例如/var/run/nginx.pid请在 service 文件中修改PIDFile为对应路径。权限问题确保 Nginx 二进制文件/usr/local/nginx/sbin/nginx和日志目录/usr/local/nginx/logs/对运行用户www可读/可写。你可以在nginx.conf中配置user指令。端口绑定如果 Nginx 监听 80 或 443 端口确保这些端口未被占用如 Apache且防火墙已放行。日常管理命令配置好 systemd 服务后你可以像管理其他系统服务一样管理 Nginx操作命令启动sudo systemctl start nginx停止sudo systemctl stop nginx重启先停再启sudo systemctl restart nginx重载配置不停机sudo systemctl reload nginx查看状态sudo systemctl status nginx开机自启sudo systemctl enable nginx取消开机自启sudo systemctl disable nginx

相关新闻

最新新闻

Webpack stats文件深度解析:Bonsai如何帮你发现隐藏的性能瓶颈

Webpack stats文件深度解析:Bonsai如何帮你发现隐藏的性能瓶颈

Webpack stats文件深度解析:Bonsai如何帮你发现隐藏的性能瓶颈 【免费下载链接】bonsai Understand the tree of dependencies inside your webpack bundles, and trim away the excess. 项目地址: https://gitcode.com/gh_mirrors/bon/bonsai 在现代前端开发…

2026/7/12 19:34:08
华为海思硬件加速器性能优化:kae_driver配置调优的7个实用技巧

华为海思硬件加速器性能优化:kae_driver配置调优的7个实用技巧

华为海思硬件加速器性能优化:kae_driver配置调优的7个实用技巧 【免费下载链接】kae_driver 项目地址: https://gitcode.com/openeuler/kae_driver 前往项目官网免费下载:https://ar.openeuler.org/ar/ 在当今高性能计算和网络安全领域&#xf…

2026/7/12 19:34:08
ChatDocs核心功能深度解析:支持12种文档格式的AI对话神器

ChatDocs核心功能深度解析:支持12种文档格式的AI对话神器

ChatDocs核心功能深度解析:支持12种文档格式的AI对话神器 【免费下载链接】chatdocs Chat with your documents offline using AI. 项目地址: https://gitcode.com/gh_mirrors/ch/chatdocs ChatDocs是一款支持本地文档与AI对话的工具,它让你无需联…

2026/7/12 19:34:08
影像系统模块概念与术语(1)

影像系统模块概念与术语(1)

影像系统的基础是相通的,但各平台的实现机制却各有千秋。我认为深入理解 Camera 系统的底层架构,不仅是夯实基础的关键,更是为了在工作中准确定位自己负责的模块,以及制定好多模块联动预案的前提。 本文基于高通 CamX 架构,梳理其中的核心名词与数据链路,并结合展锐平台进…

2026/7/12 19:34:08
对刀仪经常报 “接触过载“?内部微动结构与光电原理

对刀仪经常报 “接触过载“?内部微动结构与光电原理

对刀仪经常报接触过载🔧 搜索摘要:对刀仪维保专篇——接触式对刀仪频繁报警"接触过载"的诊断与修复。本文由宁波匠测科技(专注工业精密测量15年)基于官方手册和现场案例原创编制,强调一个重要技术细节&#…

2026/7/12 19:34:08
Zero-shot提示词效能跃迁:从准确率42%到89%的7步实战框架(附可复用模板库)

Zero-shot提示词效能跃迁:从准确率42%到89%的7步实战框架(附可复用模板库)

更多请点击: https://codechina.net 第一章:Zero-shot提示词效能跃迁:从准确率42%到89%的7步实战框架(附可复用模板库) Zero-shot提示工程并非“不给示例就靠运气”,而是通过结构化语义锚点、任务意图显式…

2026/7/12 19:29:08

月新闻