首先安装底层依赖
yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
如果需要代理成https方式访问,就需要运行下面这个指令,如果不需要则忽略
yum install -y openssl openssl-devel
安装完依赖之后,将nginx的压缩包上传到服务器上并解压(本文章以nginx-1.18.0为例)
mkdir /var/temp/nginx -p
进入解压之后的nginx文件夹(请根据实际情况)
cd nginx-1.18.0/
./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
–prefix 指定nginx安装目录
–pid-path 指向nginx的pid
–lock-path 锁定安装文件,防止被恶意篡改或误操作
–error-log 错误日志
–http-log-path http日志
–with-http_gzip_static_module 启用gzip模块,在线实时压缩输出数据流
–http-client-body-temp-path 设定客户端请求的临时目录
–http-proxy-temp-path 设定http代理的临时目录
–http-fastcgi-temp-path 设定fastcgi的临时目录
–http-uwsgi-temp-path 设定uwsgi的临时目录
–http-scgi-temp-path 设定sgi的临时目录
make && make install
备份原nginx文件
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
拷贝新的nginx启动文件到系统下
cp ./objs/nginx /usr/local/nginx/sbin/
启动nginx
/usr/local/nginx/sbin/nginx
至此,非https方式代理访问的方式已经安装完成,大家可以尝试修改nginx代理端口并重启nginx
/usr/local/nginx/sbin/nginx -s reload
以下是https方式的安装,https安装是基于http方式已经安装完成情况下升级的,所以上诉步骤不能遗漏
在nginx-1.18.0的解压目录下运行
./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make
cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak1
此处需要现将原来运行的nginx停掉
/usr/local/nginx/sbin/nginx -s stop
cp ./objs/nginx /usr/local/nginx/sbin/
重新启动nginx即可
/usr/local/nginx/sbin/nginx