Linux 安装Nginx
1. 先安装依赖 gcc PCRE zlib OpenSSL
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
2. 下载 压缩包 解压
tar zxvf nginx-1.8.0.tar.gz
3. 进入目录创建 Makefile 文件
./configure \ --prefix=/usr/local/nginx \ --pid-path=/var/run/nginx/nginx.pid \ --lock-path=/var/lock/nginx.lock \ --error-log-path=/var/log/nginx/error.log \ --http-log-path=/var/log/nginx/access.log \ --with-http_gzip_static_module \ --http-client-body-temp-path=/var/temp/nginx/client \ --http-proxy-temp-path=/var/temp/nginx/proxy \ --http-fastcgi-temp-path=/var/temp/nginx/fastcgi \ --http-uwsgi-temp-path=/var/temp/nginx/uwsgi \ --http-scgi-temp-path=/var/temp/nginx/scgi
Makefile是一种配置文件, Makefile 一个工程中的源文件不计数,其按类型、功能、模块分别放在若干个目录中,makefile定义了一系列的规则来指定,哪些文件需要先编译,哪些文件需要后编译,哪些文件需要重新编译,甚至于进行更复杂的功能操作,因为 makefile就像一个Shell脚本一样,其中也可以执行操作系统的命令。
configure参数 ./configure \ --prefix=/usr \ 指向安装目录 --sbin-path=/usr/sbin/nginx \ 指向(执行)程序文件(nginx) --conf-path=/etc/nginx/nginx.conf \ 指向配置文件 --error-log-path=/var/log/nginx/error.log \ 指向log --http-log-path=/var/log/nginx/access.log \ 指向http-log --pid-path=/var/run/nginx/nginx.pid \ 指向pid --lock-path=/var/lock/nginx.lock \ (安装文件锁定,防止安装文件被别人利用,或自己误操作。) --user=nginx \ --group=nginx \ --with-http_ssl_module \ 启用ngx_http_ssl_module支持(使支持https请求,需已安装openssl) --with-http_flv_module \ 启用ngx_http_flv_module支持(提供寻求内存使用基于时间的偏移量文件) --with-http_stub_status_module \ 启用ngx_http_stub_status_module支持(获取nginx自上次启动以来的工作状态) --with-http_gzip_static_module \ 启用ngx_http_gzip_static_module支持(在线实时压缩输出数据流) --http-client-body-temp-path=/var/tmp/nginx/client/ \ 设定http客户端请求临时文件路径 --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 设定http代理临时文件路径 --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 设定http fastcgi临时文件路径 --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 设定http uwsgi临时文件路径 --http-scgi-temp-path=/var/tmp/nginx/scgi \ 设定http scgi临时文件路径 --with-pcre 启用pcre库
编译 make
安装 make install
启动
启动nginx 之前,上边将临时文件目录指定为/var/temp/nginx/client, 需要在/var 下创建此 目录
mkdir /var/temp/nginx/client -p
进入到Nginx目录下的sbin目录
cd /usr/local/ngiux/sbin
输入命令 ./nginx
查看进程
ps aux | grep nginx
关闭 nginx
./nginx -s stop 或 ./nginx -s quit
重启 nginx 刷新配置文件
./nginx -s reload