1. 安装
1.1 源码安装
[root@localhost test]# wget http://nginx.org/download/nginx-1.22.1.tar.gz
[root@localhost test]# tar xvf nginx-1.22.1.tar.gz
[root@localhost test]# cd nginx-1.22.1
# 需要支持tcp数据转发,安装stream模块
[root@localhost nginx-1.22.1]# ./configure --without-http_rewrite_module --without-http_gzip_module --with-stream
[root@localhost nginx-1.22.1]# make -j
# 配置部署
[root@localhost nginx-1.22.1]# mkdir -p /usr/local/nginx
[root@localhost nginx-1.22.1]# mkdir -p /usr/local/nginx/logs
[root@localhost nginx-1.22.1]# cp -r conf /usr/local/nginx
[root@localhost nginx-1.22.1]# cp objs/nginx /usr/local/nginx/
[root@localhost nginx]# cd /usr/local/nginx/
[root@localhost nginx]# vim conf/nginx.conf
# 在events 配置后,添加stream 配置块
events {
worker_connections 1024;
}
stream {
server {
listen 12345;
proxy_pass 192.168.232.135:12345;
}
}
[root@localhost nginx]# ./nginx
1.2 yum安装
su - root
yum install -y nginx
systemctl start nginx.service
systemctl enable nginx.service