1.下载nginx,如果出现wget not found错误,则执行下 yum install wget
wget http://nginx.org/download/nginx-1.12.0.tar.gz
2.安装依赖
1).gcc:nginx编译依赖gcc环境 yum install gcc-c++ 2).pcre:(Perl Compatible Regular Expressions)是一个Perl库,包括 perl 兼容的正则表达式库。nginx的http模块使用pcre来解析正则表达式. yum install -y pcre pcre-devel 3).zlib:该库提供了很多种压缩和解压缩的方式,nginx使用zlib对http包的内容进行gzip。 yum install -y zlib zlib-devel 4).openssl:一个强大的安全套接字层密码库,囊括主要的密码算法、常用的密钥和证书封装管理功能及SSL协议,并提供丰富的应用程序供测试或其它目的使用。nginx不仅支持http协议,还支持https(即在ssl协议上传输http). yum install -y openssl openssl-devel
3.解压nginx,进入解压后的目录
tar -zxvf nginx-1.12.0.tar.gz
cd nginx-1.12.0
4.配置编译参数命令(命令中的一些文件夹需要手动去创建)
./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
5..编译并安装
make && make install
6.启动,适用ps -ef | grep nginx可以看到有没有nginx进程
cd /usr/local/nginx/sbin/
./nginx
6.指定配置文件方式启动,不指定默认加载conf下的nginx.conf文件
./nginx -c /usr/local/nginx/conf/nginx.conf
7.nginx一些命令
快速停止nginx,相当于杀进程 ./nginx -s stop 优雅停止,nginx处理完才停止 ./nginx -s quit