
安装流程概览安装依赖 → 下载源码 → 编译安装 → 创建 systemd 服务 → 配置防火墙 → 验证访问第一步安装编译依赖dnf install -y gcc gcc-c make pcre pcre-devel zlib zlib-devel openssl openssl-devel wget第二步下载 Nginx 源码cd /usr/local/srcwget http://nginx.org/download/nginx-1.26.2.tar.gztar -zxvf nginx-1.26.2.tar.gzcd nginx-1.26.2如需最新稳定版可到 nginx.org/download 查看版本号并替换上方链接。第三步编译并安装到 /usr/local/nginx./configure \--prefix/usr/local/nginx \--with-http_ssl_module \--with-http_v2_module \--with-http_gzip_static_modulemake -j$(nproc)make install安装完成后目录结构路径说明/usr/local/nginx/sbin/nginx可执行文件/usr/local/nginx/conf/nginx.conf主配置文件/usr/local/nginx/html/网站根目录/usr/local/nginx/logs/日志目录第四步创建 systemd 服务单元自动启动cat /etc/systemd/system/nginx.service EOF[Unit]DescriptionNginx HTTP ServerAfternetwork.target[Service]TypeforkingPIDFile/usr/local/nginx/logs/nginx.pidExecStartPre/usr/local/nginx/sbin/nginx -tExecStart/usr/local/nginx/sbin/nginxExecReload/bin/kill -s HUP $MAINPIDExecStop/bin/kill -s QUIT $MAINPIDPrivateTmptrue[Install]WantedBymulti-user.targetEOF加载并启用自动启动# 重载 systemd 配置systemctl daemon-reload# 启动 Nginxsystemctl start nginx# 设置开机自动启动systemctl enable nginx# 查看运行状态systemctl status nginx第五步配置防火墙放行 80 端口# 放行 HTTP 80 端口firewall-cmd --permanent --add-servicehttp# 如果同时需要 HTTPS 443firewall-cmd --permanent --add-servicehttps# 重载防火墙规则firewall-cmd --reload# 确认规则生效firewall-cmd --list-all第六步验证 index.html 页面Nginx 默认已在/usr/local/nginx/html/index.html生成欢迎页面可直接通过 IP 访问或自定义内容# 查看默认 index.htmlcat /usr/local/nginx/html/index.html# 自定义首页可选cat /usr/local/nginx/html/index.html EOF!DOCTYPE htmlhtmlheadmeta charsetUTF-8titleMy Server/title/headbodyh1Nginx 运行正常/h1pOpenCloudOS 9 Nginx /usr/local/nginx/p/body/htmlEOF浏览器访问http://你的服务器IP常用管理命令汇总操作命令启动systemctl start nginx停止systemctl stop nginx重启systemctl restart nginx重载配置systemctl reload nginx查看状态systemctl status nginx测试配置语法/usr/local/nginx/sbin/nginx -t查看版本/usr/local/nginx/sbin/nginx -v关键路径一览