当前位置:首页 » 代理许可 » 如何反向代理

如何反向代理

发布时间: 2021-01-04 23:44:41

A. 如何设置Nginx反向代理,我们公司现在要找个服务器做反向代理。可是我不知道怎么做。

没办法做这样的反向代理。
除非是
->
->
如果是这样的专话,配置是这样的
location /8080 {
proxy_pass ;
proxy_redirect off;
}
location /8000 {
proxy_pass ;
proxy_redirect off;
}
proxy的其它参数就自己设置了属,可以参考下

B. 如何取得反向代理的真实ip

问题引出:
<hr/>
在JSP里,获取客户端的IP地址的方法是:request.getRemoteAddr(),这种方法在大部分情况下都是有效的。但是在通过了 Apache,Nagix等反向代理软件就不能获取到客户端的真实IP地址了。如果使用了反向代理软件,用 request.getRemoteAddr()方法获取的IP地址是:127.0.0.1或 192.168.1.110,而并不是客户端的真实IP。
经过代理以后,由于在客户端和服务之间增加了中间层,因此服务器无法直接拿到客户端的 IP,服务器端应用也无法直接通过转发请求的地址返回给客户端。但是在转发请求的HTTP头信息中,增加了X-FORWARDED-FOR信息。用以跟踪原有的客户端 IP地址和原来客户端请求的服务器地址。
举例来说,当我们访问口碑网首页hangzhou.jsp时,其实并不是我们浏览器真正访问到了服务器上的hangzhou.jsp 文件,而是先由代理服务器Nagix去访问hagnzhou.jsp ,代理服务器再将访问到的结果返回给我们的浏览器,因为是代理服务器去访问hangzhou.jsp的,所以hangzhou.jsp中通过 request.getRemoteAddr()的方法获取的IP实际上是代理服务器的地址,并不是客户端的IP地址。
<hr/>
获得客户端真实IP地址的方法一:
public String getRemortIP(HttpServletRequest request) {
if (request.getHeader("x-forwarded-for") == null) {
return request.getRemoteAddr();
}
return request.getHeader("x-forwarded-for");
}
<hr/>

获得客户端真实IP地址的方法二

public String getIpAddr(HttpServletRequest request) {
String ip = request.getHeader("x-forwarded-for");
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getHeader("WL-Proxy-Client-IP");
}
if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
ip = request.getRemoteAddr();
}
return ip;
}
<hr/>

C. 如何使用nginx设置反向代理

修改部署目录下conf子目录的nginx.conf文件(如nginx-1.5.13conf ginx.conf)内容,可调整相关配置。
反向代理配置示例:

location/{
#设置主机头和客户端真实地址,以便服务器获取客户端真实IP
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

#禁用缓存
proxy_bufferingoff;

#设置反向代理的地址
proxy_passhttp://192.168.1.1;
}

代理地址根据实际情况修改。

D. 如何取得反向代理的真实IP

||

取得反向代理的真实IP的方法有两种:

一,public String getRemortIP(HttpServletRequest request)

if (request.getHeader("x-forwarded-for") == null)


return request.getRemoteAddr();

return request.getHeader("x-forwarded-for")。



二,
public String getIpAddr(HttpServletRequest request)


String ip = request.getHeader("x-forwarded-for");


if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))


ip = request.getHeader("Proxy-Client-IP");



if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))


ip = request.getHeader("WL-Proxy-Client-IP")。




E. 如何给Proxmox设置反向代理

用虚拟机nginx做

F. web服务器反向代理 怎么理解

简单说
我们内网访问facebook用的代理就叫正向代理

从美国访问我们内网需要的代理就叫反向代理

多台服务器处于一个内网,而我们要访问这些服务器,中间加一台 反向代理,根据各台服务器的负载,指定访问其中一台。这就叫负载均衡。
反向代理一般就是来干这个的

代理服务器来接受外部的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给外部的请求连接的客户端,此时代理服务器对外就表现为一个服务器。

反向代理一般作用:
1:减轻源服务器负载
2:保障源服务器安全
3:对源服务器进行负载均衡(Load Balance)。

G. 什么是反向代理服务器如何配置反向代理服务器

反向代理服务器是运行有反向代理程序的计算机,通过反向代理,可以绕开端口限制,将一个URL转发到另一个URL,解决80端口问题等。目前比较成熟的开放的反向代理应用有nginx和nat123。ngnix是单纯的反向代理,可以利用nginx自行搭建反向代理服务,不少运营商甚至拿来包装成自己的界面,来运营。nat123是综合了NAT和反向代理,一般用户可以直接用nat123提供的反向代理服务,无需自己再搭建。

H. 如何通过反向代理服务器获取数据

upstream cjdby{
server pigoss;
server tianyuan;
}
在server节点中,只保留一下location,然后把proxy_pass改成这样

proxy_pass http://cjdby;
其它的set_header不变

I. 怎么测试nginx反向代理

代理机器:192.168.163.128

后端机器:192.168.163.129和192.168.163.131

以上三台机器都搭建了nginx

1、修改index.html,区别后端机器

192.168.163.129和192.168.163.131上的/usr/local/nginx/html/index.html中,修改Welcome to nginx 为Welcome to nginx129和Welcome to nginx131以作这两台机器的区别

2、代理机器的配置

修改nginx.conf文件:

[html]view plain

  • http{

  • includemime.types;

  • default_typeapplication/octet-stream;

  • include/usr/local/nginx/conf/reverse-proxy.conf;

  • #log_formatmain'$remote_addr-$remote_user[$time_local]"$request"'

  • #'$status$body_bytes_sent"$http_referer"'

  • #'"$http_user_agent""$http_x_forwarded_for"';

  • #access_loglogs/access.logmain;

  • sendfileon;

  • #tcp_nopushon;

  • #keepalive_timeout0;

  • keepalive_timeout65;

  • gzipon;

  • client_max_body_size50m;#缓冲区代理缓冲用户端请求的最大字节数,可以理解为保存到本地再传给用户

  • client_body_buffer_size256k;

  • client_header_timeout3m;

  • client_body_timeout3m;

  • send_timeout3m;

  • proxy_connect_timeout300s;#nginx跟后端服务器连接超时时间(代理连接超时)

  • proxy_read_timeout300s;#连接成功后,后端服务器响应时间(代理接收超时)

  • proxy_send_timeout300s;

  • proxy_buffer_size64k;#设置代理服务器(nginx)保存用户头信息的缓冲区大小

  • proxy_buffers432k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置

  • proxy_busy_buffers_size64k;#高负荷下缓冲大小(proxy_buffers*2)

  • proxy_temp_file_write_size64k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传递请求,而不缓冲到磁盘

  • proxy_ignore_client_aborton;#不允许代理端主动关闭连接

  • #gzipon;

  • server{

  • listen80;

  • server_namelocalhost;

  • #charsetkoi8-r;

  • #access_loglogs/host.access.logmain;

  • location/{

  • roothtml;

  • indexindex.htmlindex.htm;

  • }

  • #error_page404/404.html;

  • #/50x.html

  • #

  • error_page500502503504/50x.html;

  • location=/50x.html{

  • roothtml;

  • }

  • 3、添加conf/reverse-proxy.conf文件

    [html]view plain

  • server

  • {

  • listen80;

  • server_name123.tk;

  • location/{

  • proxy_redirectoff;

  • proxy_set_headerHost$host;

  • proxy_set_headerX-Real-IP$remote_addr;

  • proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

  • proxy_passhttp://192.168.163.129:80;

  • }

  • access_loglogs/123.tk_access.log;

  • }

  • server

  • {

  • listen80;

  • server_name456.tk;

  • location/{

  • proxy_redirectoff;

  • proxy_set_headerHost$host;

  • proxy_set_headerX-Real-IP$remote_addr;

  • proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;

  • proxy_passhttp://192.168.163.131:80;

  • }

  • access_loglogs/456.tk_access.log;

  • }


  • 4、重载nginx

    kill -HUP `cat /usr/local/nginx/nginx.pid`

    5、修改访问机器的hosts

    在要访问这些域名的机器上修改hosts文件,添加:

    [html]view plain

  • 192.168.163.129123.tk

  • [html]view plain

  • 192.168.163.131456.tk

  • 6、测试访问


热点内容
美发店认证 发布:2021-03-16 21:43:38 浏览:443
物业纠纷原因 发布:2021-03-16 21:42:46 浏览:474
全国著名不孕不育医院 发布:2021-03-16 21:42:24 浏览:679
知名明星确诊 发布:2021-03-16 21:42:04 浏览:14
ipad大专有用吗 发布:2021-03-16 21:40:58 浏览:670
公务员协议班值得吗 发布:2021-03-16 21:40:00 浏览:21
知名书店品牌 发布:2021-03-16 21:39:09 浏览:949
q雷授权码在哪里买 发布:2021-03-16 21:38:44 浏览:852
图书天猫转让 发布:2021-03-16 21:38:26 浏览:707
宝宝水杯品牌 发布:2021-03-16 21:35:56 浏览:837