Nginx 安装教程

举报
yd_278385342 发表于 2026/11/08 22:31:38 2026/11/08
【摘要】 Ubuntu / Debianbashsudo apt updatesudo apt install nginx -ysudo systemctl start nginxsudo systemctl enable nginxsudo systemctl status nginx验证:浏览器访问 http://服务器IP,出现 Welcome to nginx! 即成功。CentOS / RH...

Ubuntu / Debian

bash
sudo apt update
sudo apt install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

验证:浏览器访问 http://服务器IP,出现 Welcome to nginx! 即成功。


CentOS / RHEL

bash
sudo yum install epel-release -y
sudo yum install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx

Windows

  1. 下载:https://nginx.org/en/download.html 选择 Stable 版 Windows 压缩包。

  2. 解压到无中文、无空格路径,如 C:\nginx。

  3. 启动:

cmd
cd C:\nginx
start nginx
  1. 验证:浏览器访问 http://localhost。

  2. 停止:

cmd
nginx -s stop

源码编译安装(Linux)

bash
# Ubuntu / Debian 依赖
sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev -y

# CentOS / RHEL 依赖
sudo yum install gcc pcre-devel zlib-devel openssl-devel -y

cd /usr/local/src
sudo wget https://nginx.org/download/nginx-1.26.3.tar.gz
sudo tar -zxvf nginx-1.26.3.tar.gz
cd nginx-1.26.3

sudo ./configure --prefix=/usr/local/nginx --with-http_ssl_module --with-http_stub_status_module
sudo make
sudo make install

sudo /usr/local/nginx/sbin/nginx

验证:

bash
curl -I http://127.0.0.1

常用命令

bash
sudo nginx -t                 # 检查配置
sudo systemctl reload nginx   # 重载配置
sudo systemctl restart nginx  # 重启
sudo systemctl stop nginx     # 停止
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0)

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。