2.上传至Linux /my/nginx
3.解压nginx
tar -zxvf nginx-1.9.8.tar.gz
4.nginx环境安装
1)安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没有gcc环境,需要安装gcc
yum install gcc-c++
2)PCRE(PerlCompatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式,所以需要在linux上安装pcre库。
yum install -y pcre pcre-devel
3) zlib库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip,所以需要在linux上安装zlib库
yum install -y zlib zlib-devel
4)OpenSSL 是一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http),所以需要在linux安装openssl库。
yum install -yopenssl openssl-devel
5.编译安装
1) configure
./configure --help查看详细参数
2)参数设置如下
创建如下文件夹
# mkdir -p temp/nginx
执行如下配置命令
./configure \
--prefix=/my/nginx/nginx-single \
--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
3)编译
make
make install
6.启动nginx
cd /my/nginx/nginx-single/sbin
./nginx
查看nginx 进程 ps -ef|grep nginx
68948为主进程id
68949为工作进程id
./nginx -c /my/nginx/nginx-single/conf/nginx.conf
指定加载nginx的配置文件
停止
./nginx -s stop
./nginx -s quit
重启nginx
./nginx -s quit
./nginx
重新加载配置文件:
当nginx的配置文件nginx.conf修改后,要想让配置生效需要重启nginx,使用-s reload不用先停止nginx再启动nginx即可将配置信息在nginx中生效,如下:
./nginx -s reload
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall开机启动