ContOS7中使用Nginx进行TCP反向代理

一、安装Nginx

1.下载: http://nginx.org/en/download.html

wget http://nginx.org/download/nginx-1.16.1.tar.gz

2.解压

tar -zxvf nginx-1.16.1.tar.gz
cd nginx-1.16.1

3.安装环境

yum install gcc-c++
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel

4.安装配置

./configure --with-stream

5.编译安装

make
make install

二、参数配置

1.找到并进入安装的路径

whereis nginx
nginx: /usr/local/nginx
cd /usr/local/nginx

2.配置nginx.conf中的参数

vim conf/nginx.conf

添加如下配置,参数自行修改:

stream {
    server {
        listen 5880;
        proxy_connect_timeout 30s;
        proxy_timeout 30s;
        proxy_pass 192.168.1.1:3366;
    }      
}

3.重启nginx服务,在nginx/sbin目录下

./nginx -s reload

三、遇到的问题

1.重启服务遇到:nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
我来评几句
登录后评论

已发表评论数()

相关站点

热门文章