源码安装 Nginx 1.23.1

一. 备份和删除老的nginx

yum remove -y nginx
cd /etc/nginx
tar -czf /home/nginx.tar.gz *
cp nginx.conf nginx.auto.conf /home/
rm -rf /etc/nginx
rm -rf /usr/sbin/nginx

二. 备份iptables策略、开辟关闭nginx后无法远程控制的通道

iptables-save >/home/ipts.bak
/sbin/iptables -t nat -A PREROUTING -s 123.119.238.110 -p tcp --dport 18023 -j DNAT --to 192.168.0.100:63389
/sbin/iptables -t nat -A POSTROUTING -p tcp --dport 63389 -j MASQUERADE
/sbin/iptables -t filter -I FORWARD -j ACCEPT

三. 安装nginx 1.23.1

yum -y install openssl openssl-devel make zlib zlib-devel gcc gcc-c++ libtool    pcre pcre-devel pam pam-devel
tar -xvzf nginx-1.23.1.tar.gz
cd nginx-1.23.1
./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-pcre --with-http_ssl_module --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_realip_module --with-http_addition_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-threads --with-file-aio
make && make install

四. 还原配置文件

cd /etc/nginx/conf
cp /home/nginx.conf /home/nginx.auto.conf ./
mkdir /etc/nginx/logs

四. 启动nginx

nginx
ps -ef|grep nginx

你可能感兴趣的:(杂项,nginx,运维,linux)