博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx四层网络代理实现
阅读量:4200 次
发布时间:2019-05-26

本文共 1366 字,大约阅读时间需要 4 分钟。

1.下载源码

wget http://nginx.org/download/nginx-1.14.0.tar.gztar -xzf nginx-1.14.0.tar.gzcd nginx-1.14.0

2.编译环境

Debian 环境需要安装的软件包

apt install gcc makeapt install libpcre3 libpcre3-dev  //【正则表达式库】 官网http://www.pcre.org/apt install openssl libssl-dev     //【openssl库】 官网https://www.openssl.org/apt install zlib1g-dev

3.nginx的编译与安装

./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_ssl_module --with-http_stub_status_module --with-file-aio --with-streammake && make install

4.配置nginx配置文件

vim /usr/local/nginx/conf/nginx.conf

配置是ip和端口是需要代理的地址端口,listen的端口是提供给外部用来访问的端口

worker_processes  1;events {    worker_connections  1024;}stream {          upstream tcp_proxy {        hash $remote_addr consistent;  #远程地址做个hash        server 192.168.230.131:22;   }      server {        listen 2222;        proxy_connect_timeout 1s;        proxy_timeout 36000s;  #后端连接超时时间        proxy_pass tcp_proxy;     }  }

5.启动nginx服务

/usr/local/nginx/sbin/nginx

6.测试nginx

查看端口映射

netstat -ntpl|grep 2222tcp        0      0 0.0.0.0:2222            0.0.0.0:*               LISTEN      13661/nginx: master

测试远程ssh访问

ssh -p 2222 th@10.95.42.136th@10.95.42.136's password: Last login: Sat Apr  8 22:32:14 2017 from linux-node1[root@linux-node2 ~]# lstest.txt

7.过程中遇到的错误:找不到www用户

错误日志

./sbin/nginx nginx: [emerg] getpwnam("www") failed

解决方法,添加www用户

groupadd -f wwwuseradd -g www www

转载地址:http://llfli.baihongyu.com/

你可能感兴趣的文章
【GoLang】Web工作方式
查看>>
Launch Sublime Text 3 from the command line
查看>>
【数据库之mysql】mysql的安装(一)
查看>>
【数据库之mysql】 mysql 入门教程(二)
查看>>
【HTML5/CSS/JS】A list of Font Awesome icons and their CSS content values(一)
查看>>
【HTML5/CSS/JS】<br>与<p>标签区别(二)
查看>>
【HTML5/CSS/JS】开发跨平台应用工具的选择(三)
查看>>
【心灵鸡汤】Give it five minutes不要让一个好主意随风而去
查看>>
【React Native】Invariant Violation: Application AwesomeProject has not been registered
查看>>
【ReactNative】真机上无法调试 could not connect to development server
查看>>
【XCode 4.6】常用快捷键 特别是格式化代码ctrl+i
查看>>
【iOS游戏开发】icon那点事 之 实际应用(二)
查看>>
【iOS游戏开发】icon那点事 之 图标设计(三)
查看>>
【IOS游戏开发】之测试发布(Distribution)
查看>>
【IOS游戏开发】之IPA破解原理
查看>>
【一天一道LeetCode】#45. Jump Game II
查看>>
【一天一道LeetCode】#46. Permutations
查看>>
【一天一道LeetCode】#47. Permutations II
查看>>
【一天一道LeetCode】#48. Rotate Image
查看>>
【一天一道LeetCode】#56. Merge Intervals
查看>>