下载nginx
官网下载:http://nginx.org/ 选择最新 stable稳定版本就可以
选择稳定版本后,点击进去选择下载,下图左边是linux版本,右边是windows版本,我们下载linux版本
解压和编译安装
把文件上传在服务器中,我是上传在 /home/nginx 目录下
解压命令:tar -zvxf nginx-1.14.0.tar.gz
解压成功后:cd nginx-1.14.0
编译命令: ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module
如果是新环境,编译安装之前需要准备一些软件支持,编译过程中出现的一些错误和解决方式:
1.(./configure: error: C compiler cc is not found)
解决: yum install -y gcc gcc-c++
2../configure: error: the HTTP rewrite module requires the PCRE library
解决:yum -y install pcre-devel
3../configure: error: the HTTP gzip module requires the zlib library
解决:yum install -y zlib-devel
4../configure: error: the ssl module require the openssl library
解决:yum -y install openssl openssl-devel
安装命令: make && make install
nginx运行、停止、重启
前往nginx安装目录:cd /usr/local/nginx
启动nginx:./sbin/nginx
编辑conf/nginx.conf之后,可以不用停止nginx直接重新加载就可以:./sbin/nginx -s reload
停止nginx:./sbin/nginx -s stop