centos/Ubuntu安装Nginx服务器

安装方式

  1. 使用系统自带的软件包管理器快速安装(如centos的yum)
  2. 到官网下载压缩包安装(https://nginx.org/en/download.html)
  3. docker容器实例

下面是昨天以第二种方式安装的命令小记!

centos

shell 复制代码
# 下载(https://nginx.org/en/download.html官网复制相应版本下载地址)
curl -o nginx-1.21.6.tar.gz http://nginx.org/download/nginx-1.21.6.tar.gz

# 解压
tar -zxvf nginx-1.21.6.tar.gz

# 安装相关环境依赖
yum install pcre pcre-devel -y
yum install openssl openssl-devel -y

# 生成编译脚本
./configure --with-http_ssl_module --withhttp_v2_module --with-stream

# 编译
make

# 开始安装
make install

# 检查是否成功安装
ls /usr/local/nginx/
ls /usr/local/nginx/sbin/
sudo /usr/local/nginx/sbin/nginx -t

# 配置环境变量
vim /etc/profile

# 在最后一行添加以下内容
export PATH=$PATH:/usr/local/nginx/sbin

# 刷新环境配置
source /etc/profile

# 启动
nginx

# 查看启动情况
netstat -ntlp

Ubuntu

shell 复制代码
下载(https://nginx.org/en/download.html官网复制相应版本下载地址)
curl -o nginx-1.21.6.tar.gz http://nginx.org/download/nginx-1.21.6.tar.gz

# 解压
tar -zxvf nginx-1.21.6.tar.gz

# 安装相关环境依赖
sudo apt install gcc make libpcre3-dev zlib1g-dev openssl libssl-dev

# 生成编译脚本
./configure --prefix=/usr/local/nginx --with-http_ssl_module

# 编译
make

# 开始安装
make install

# 检查是否成功安装
ls /usr/local/nginx/
ls /usr/local/nginx/sbin/
sudo /usr/local/nginx/sbin/nginx -t

# 配置环境变量
vim /etc/profile

# 在最后一行添加以下内容
export PATH=$PATH:/usr/local/nginx/sbin

# 刷新环境配置
source /etc/profile

# 启动
nginx

# 查看启动情况
netstat -ntlp
相关推荐
xy1230612 小时前
OpenStack Train 部署实战(三)控制节点--keystone服务
centos·openstack
Sinclair2 天前
简单几步,安卓手机秒变服务器,安装 CMS 程序
android·服务器
Rockbean3 天前
用40行代码搭建自己的无服务器OCR
服务器·python·deepseek
茶杯梦轩3 天前
CompletableFuture 在 项目实战 中 创建异步任务 的核心优势及使用场景
服务器·后端·面试
海天鹰4 天前
【免费】PHP主机=域名+解析+主机
服务器
不是二师兄的八戒4 天前
Linux服务器挂载OSS存储的完整实践指南
linux·运维·服务器
欧云服务器4 天前
怎么让脚本命令可以同时在centos、debian、ubuntu执行?
ubuntu·centos·debian
芝士雪豹只抽瑞克五4 天前
Nginx 高性能Web服务器笔记
服务器·nginx
智渊AI4 天前
Ubuntu 20.04/22.04 下通过 NVM 安装 Node.js 22(LTS 稳定版)
ubuntu·node.js·vim
失重外太空啦4 天前
Tomcat
java·服务器·tomcat