Nginx 安装与启动教程​

Nginx 安装与启动教程​

Nginx 安装与启动教程 ​在使用 Nginx 前,需要先完成安装与服务启动。本节将介绍在 Linux、Windows、macOS 等平台上安装与运行 Nginx 的方法,并提供验证与命令示例。

一、Linux 下安装 Nginx ​1. 使用包管理器安装 ​🟢 CentOS / Rocky Linux / RHEL 系列 ​bashsudo yum install epel-release -y

sudo yum install nginx -y🔵 Ubuntu / Debian 系列 ​bashsudo apt update

sudo apt install nginx -y2. 启动与开机自启 ​bashsudo systemctl start nginx

sudo systemctl enable nginx3. 验证安装 ​在浏览器中访问: 👉 http://localhost 如果看到 “Welcome to Nginx” 页面,则说明安装成功。

二、Windows 下安装 Nginx ​前往 nginx官网 下载 Windows 版压缩包。解压后进入目录,例如 C:\nginx。在命令提示符中运行:bashstart nginx访问 http://localhost 验证是否启动成功。停止 Nginx:

bashnginx -s stop重新加载配置:

bashnginx -s reload三、macOS 安装 Nginx ​通过 Homebrew 安装:

bashbrew install nginx启动服务:

bashbrew services start nginxNginx 默认运行在端口 8080,可访问 👉 http://localhost:8080

四、验证与常用命令 ​命令功能说明nginx -t检查配置文件语法是否正确nginx -s reload热加载配置文件nginx -s stop停止 Nginx 服务nginx -v查看 Nginx 版本systemctl status nginx查看 Nginx 运行状态五、常见问题 ​80 端口被占用:修改 nginx.conf 的 listen 端口或关闭冲突进程。启动失败:检查配置文件错误,执行 nginx -t 验证后再启动。权限不足:使用 sudo 运行或调整文件权限。通过本节学习,你已掌握 Nginx 的安装、启动与验证方式,为后续配置与优化打下基础。

相关推荐

合成表 - 铜制号角 (Copper Horn) - [MC]我的世界原版 (Minecraft) - MC百科
k1156次列车卧铺票多少钱
365体育直播

k1156次列车卧铺票多少钱

09-22 3788
cf体验服是多久开服的?
365体育中国

cf体验服是多久开服的?

09-27 3365