Nginx 安装指南

一、Linux packages 方式安装

1. 各个服务器版本选择

  1. RHEL/CentOS:
  2. Version Supported Platforms
  3. 6.x x86_64, i386
  4. 7.4+ x86_64, ppc64le
  5. Ubuntu:
  6. Version Codename Supported Platforms
  7. 14.04 trusty x86_64, i386, aarch64/arm64
  8. 16.04 xenial x86_64, i386, ppc64el, aarch64/arm64
  9. 17.04 zesty x86_64, i386
  10. Debian:
  11. Version Codename Supported Platforms
  12. 8.x jessie x86_64, i386
  13. 9.x stretch x86_64, i386
  14. SLES:
  15. Version Supported Platforms
  16. 12 x86_64

2. 安装指定版本的 nginx

  1. 1. 配置指定服务器适合的 nginx 版本
  2. a) RHEL / CentOS
  3. # 模板
  4. [nginx 模板]
  5. name=nginx repo
  6. baseurl=http://nginx.org/packages/OS/OSRELEASE/$basearch/
  7. gpgcheck=0
  8. enabled=1
  9. # 模板参数
  10. OS: 替换成对应的操作系统
  11. OSRELEASE: 替换成操作系统版本
  12. # 案例: centos 7 环境配置
  13. sudo vim /etc/yum.repos.d/nginx.repo
  14. [nginx]
  15. name=nginx repo
  16. baseurl=http://nginx.org/packages/centos/7/$basearch/
  17. gpgcheck=0
  18. enabled=1
  19. b) Debian / Ubuntu
  20. # 模板
  21. deb http://nginx.org/packages/ubuntu/ codename nginx
  22. deb-src http://nginx.org/packages/ubuntu/ codename nginx
  23. # 模板参数
  24. codename: 详见(各个服务器版本选择) 中的 Codename
  25. # 案例: Ubuntu 16.04 xenial
  26. sudo vim /etc/apt/sources.list
  27. # nginx
  28. deb http://nginx.org/packages/ubuntu/ xenial nginx
  29. deb-src http://nginx.org/packages/ubuntu/ xenial nginx
  30. 3. 验证签名秘钥
  31. # 下载签名
  32. wget http://nginx.org/keys/nginx_signing.key --directory-prefix=/tmp/
  33. # RHEL / CentOS
  34. sudo rpm --import /tmp/nginx_signing.key
  35. # Debian / Ubuntu
  36. sudo apt-key add /tmp/nginx_signing.key
  37. 4. 安装
  38. a) RHEL / CentOS
  39. # 验证源是否生效
  40. sudo yum repolist all | grep nginx
  41. # 生效源
  42. sudo yum makecache
  43. # 执行安装
  44. sudo yum install nginx
  45. # 查看是否安装成功
  46. nginx -v 查看 nginx 版本
  47. nginx -V 查看 nginx 编译参数

二. 使用

  1. nginx 启动
  2. nginx -s stop 快速关闭
  3. nginx -s quit 退出(关闭), 这个会等待 Nginx 处理完当前请求
  4. nginx -s reload 重新加载配置文件
  5. nginx -s reopen 重新打开日志文件