需求背景:
前段时间公司因为业务需求需要部署一个正向代理,我已经分享出来了https://www.cnblogs.com/Dfengshuo/p/11911406.html,现有因架构个更改,需要再加个在原先的反向代理下再加一层,ok,其实还是挺鸡肋的,但是没办法,领导安排就要根据安排需求做。其实nginx反向代理分两种,四层网络层代理和七层应用层代理,想要实现这两种模式很简单,只是配置文件略微不同而已。今天分享一下四层协议的代理吧!
首先安装nginx环境:
1 yum -y install pcre-devel zlib-devel gcc gcc+c++ make openssl openssl-devel
2 tar xf nginx-1.11.4.tar.gz
3 cd nginx-1.11.4/
4 ./configure --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_stub_status_module --with-pcre --with-stream && make && make install
View Code
编译安装完毕后进行更改nginx配置文件,配置四层协议反向代理
bash;collapse:true;;gutter:true;</p>
<h1>user nobody;</h1>
<p>worker_processes 1;</p>
<h1>error_log logs/error.log;</h1>
<h1>error_log logs/error.log notice;</h1>
<h1>error_log logs/error.log info;</h1>
<h1>pid logs/nginx.pid;</h1>
<p>events {
worker_connections 1024;
}</p>
<p>http {
include mime.types;
default_type application/octet-stream;</p>
<pre><code>#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
}
}
</code></pre>
<p>}
配置完成后保存重启nginx即可,进行测试,结果表明成功!
Original: https://www.cnblogs.com/Dfengshuo/p/11911663.html
Author: fs_Dong
Title: 搭建Nginx四层反向代理
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/585727/
转载文章受原作者版权保护。转载请注明原作者出处!