Ubuntu安装及升级Nginx

系统环境:Ubuntu 16.04

1、安装nginx

# 简单安装
apt-get install nginx

# 安装完整版(包含所有模块)
apt-get install nginx-full

2、升级nginx

# 安装相关软件
apt install software-properties-common

# 运行命令
apt-add-repository ppa:nginx/stable

升级:

apt-get update

apt-get install nginx-full

升级nginx使用的源是Nginx Stable PPA,属于Ubuntu社区维护的源,本源更新自稳定版分支,这个源的特点是文件的目录结构和Ubuntu自带的Nginx相同,因此安装这个版本时不需要修改/etc/nginx/下面的配置文件。但是这个源更新比较慢,一般Nginx 新版本发布后要过一至两周才会更新,但质量是保证的。

不过这个源将SPDY作为额外模块,因此如果你需要启用SPDY或者执行service nginx start后没有反应则应该运行以下命令:

apt-get install nginx-extras

3、日常管理nginx

# 启动
/etc/init.d/nginx start

# 停止
service nginx stop

# 重启
service nginx restart

# 检测是否存在错误
nginx -t

# 查看安装版本
nginx -v

# 查看安装详细版本以及依赖
nginx -V


评论