安装

安装依赖

prce(重定向支持)和openssl(https支持,如果不需要https可以不安装。)

  1. yum install -y pcre-devel
  2. yum -y install gcc make gcc-c++ wget
  3. yum -y install openssl openssl-devel

CentOS 6.5 我安装的时候是选择的“基本服务器”,默认这两个包都没安装全,所以这两个都运行安装即可。

下载

nginx的所有版本在这里

  1. wget http://nginx.org/download/nginx-1.13.3.tar.gz
  2. wget http://nginx.org/download/nginx-1.13.7.tar.gz
  3. # 如果没有安装wget
  4. # 下载已编译版本
  5. $ yum install wget
  6. # 解压压缩包
  7. tar zxf nginx-1.13.3.tar.gz

编译安装

然后进入目录编译安装,configure参数说明

  1. cd nginx-1.11.5
  2. ./configure
  3. ....
  4. Configuration summary
  5. + using system PCRE library
  6. + OpenSSL library is not used
  7. + using system zlib library
  8. nginx path prefix: "/usr/local/nginx"
  9. nginx binary file: "/usr/local/nginx/sbin/nginx"
  10. nginx modules path: "/usr/local/nginx/modules"
  11. nginx configuration prefix: "/usr/local/nginx/conf"
  12. nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
  13. nginx pid file: "/usr/local/nginx/logs/nginx.pid"
  14. nginx error log file: "/usr/local/nginx/logs/error.log"
  15. nginx http access log file: "/usr/local/nginx/logs/access.log"
  16. nginx http client request body temporary files: "client_body_temp"
  17. nginx http proxy temporary files: "proxy_temp"
  18. nginx http fastcgi temporary files: "fastcgi_temp"
  19. nginx http uwsgi temporary files: "uwsgi_temp"
  20. nginx http scgi temporary files: "scgi_temp"

安装报错误的话比如:“C compiler cc is not found”,这个就是缺少编译环境,安装一下就可以了 yum -y install gcc make gcc-c++ openssl-devel

如果没有error信息,就可以执行下边的安装了:

  1. make
  2. make install

nginx测试

运行下面命令会出现两个结果,一般情况nginx会安装在/usr/local/nginx目录中

  1. cd /usr/local/nginx/sbin/
  2. ./nginx -t
  3. # nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  4. # nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

设置全局nginx命令

  1. vi ~/.bash_profile

将下面内容添加到 ~/.bash_profile 文件中

  1. PATH=$PATH:$HOME/bin:/usr/local/nginx/sbin/
  2. export PATH

运行命令 source ~/.bash_profile 让配置立即生效。你就可以全局运行 nginx 命令了。