本博文介绍Nginx在Windows 10、Ubuntu16.04、Centos7下的安装方法
Linux安装方法主要参考官网:http://nginx.org/en/linux_packages.html
Windows 10
在Windows下安装相对简单,只需要下载安装包,解压即可。
1.下载安装包
http://nginx.org/en/download.html,选择Stable version(最新的稳定版本)下载
2.解压安装
右键ngin-1.16.0.zip-->解压到当前文件夹
得到如下文件夹
3.启动
进入解压后的文件夹nginx-1.16.0,双击nginx.exe启动nginx服务器
4.测试
浏览器输入localhost:80或者localhost,看到Welcome to nginx为安装成功。
Ubuntu16.04
1.安装必要的包
sudo apt install curl gnupg2 ca-certificates lsb-release
2.设置apt仓库安装最新稳定版本的nginx,执行以下命令
echo "deb http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
| sudo tee /etc/apt/sources.list.d/nginx.list
3.导入官方签名密钥
curl -fsSL https://nginx.org/keys/nginx_signing.key | sudo apt-key add -
4.验证key
sudo apt-key fingerprint ABF5BD827BD9BF62
执行后会有如下输出
pub rsa2048 2011-08-19 [SC] [expires: 2024-06-14]
573B FD6B 3D8F BC64 1079 A6AB ABF5 BD82 7BD9 BF62
uid [ unknown] nginx signing key <signing-key@nginx.com>
5.安装nginx
sudo apt update
sudo apt install nginx
6.启动nginx
service nginx start
7.测试
浏览器输入ip:80或主机名称:80
Centos7
1.安装必要的包
sudo yum install yum-utils
2.新建nginx.repo文件
sudo nano /etc/yum.repos.d/nginx.repo
nginx.repo文件内容如下:
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
4.安装nginx
sudo yum install nginx
5.启动nginx
sudo service nginx start
6.测试
完成! enjoy it!