一:安装依赖(已安装可忽略此步骤)
yum -y install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel open openssl-devel
二:下载nginx安装包
wget http://nginx.org/download/nginx-1.16.1.tar.gz
三:解压nginx
1.编译如果提示./configure: error: the HTTP rewrite module requires the PCRE library.,则执行yum -y install pcre-devel后重新编译
2.提示./configure: error: the HTTP gzip module requires the zlib library.,则执行yum install -y zlib-devel后重新编译
// 1.解压nginx
tar -zxvf nginx-1.16.1.tar.gz
// 2.解压完成后,切换到nginx目录
cd nginx-1.16.1/
// 3.需要使用https执行指令
./configure --with-http_ssl_module
// or 不需要使用https执行
./configure
四:执行安装命令
// 1.执行安装命令
make && make install
// 2.查看编译参数
./configure --help | more
五:开放访问端口80(可自定义,可忽略)
// 不同centos 系统指令有差别
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
六:更改nginx.conf文件
// 1.切换到conf目录
cd usr/local/nginx/conf
// 2.编辑redis.conf
vi redis.conf
1.修改端口号,这里默认使用的8088,因为80可能会让apahce占用
2.修改location,注释掉暂用不到的页面参数,添加proxy_pass,后跟需要跳转的地址
3.保存
// 保存
:wq
七:查看配置文件是否正确
cd /usr/local/nginx/sbin
./nginx -t
结果:
八:运行
// 切换到sbin文件夹下
cd /usr/local/nginx/sbin
// 默认配置文件启动
./nginx
// 指定配置文件启动
./nginx -c /usr/local/nginx/conf/nginx.conf
// 停止指令
./nginx -s stop