Nginx配置proxy_pass转发的/路径

请求原地址 :http://servername/static_js/test.html

复制代码

location ^~ /static_js/ 
{ 
    proxy_cache js_cache; 
    proxy_set_header Host js.test.com; 
    proxy_pass http://js.test.com/; 
}

或者 使用rewrite

location ^~ /static_js/ 
{ 
    proxy_cache js_cache; 
    proxy_set_header Host js.test.com; 
    rewrite /static_js/(.+)$ /$1 break; 
    proxy_pass http://js.test.com; 
} 

复制代码

代理成 http://js.test.com/test.html

复制代码

location ^~ /static_js/ 
{ 
    proxy_cache js_cache; 
    proxy_set_header Host js.test.com; 
    proxy_pass http://js.test.com; 
}

复制代码

代理成 http://js.test.com/static_js/test.htm

域名跳转 访问 crm6yy_proxy.xxx.com    跳转到  crm6yy.xxx.com

1

2

3

4

5

6

7

8

9

10

11

server {

        listen 80  ;

        server_name crm6yy_proxy.xxx.com;

        location / {

            proxy_set_header Host $host;

            proxy_set_header X-Real-Ip $remote_addr;

            proxy_set_header X-Forwarded-For $remote_addr;

            proxy_pass http://crm6yy.xxx.com/;

        }

}   

  正向代理 

场景

A 不能上外网

B 能上外网 (A和B可以互相访问)

C 外面的网站 http://www.baidu.com

B上nginx配置如下代码

复制代码

resolver 8.8.8.8;  
    server {  
        listen       8090;  
  
        location / {  
                proxy_pass $scheme://$http_host$request_uri;  
        }  
    }

复制代码

使用:

在A机器访问:

或者 curl -x B:8090 -k "C"

或者 export http_proxy="http://B:8090"

或者windows下:在internet选项->连接->局域网设置->代理服务器 填入ip及端口即可

猜你喜欢

转载自my.oschina.net/newchaos/blog/1795572