`

运维:Nginx Location if语句中proxy_pass 不支持/context 虚拟路径的解决方案。

阅读更多

请看官方的说明,你可以找到思路 ^_^

A special case is using variables in the proxy_pass statement: The requested URL is not used and you are fully responsible to construct the target URL yourself.

This means, the following is not what you want for rewriting into a zope virtual host monster, as it will proxy always to the same URL (within one server specification):

location / {
  proxy_pass   http://127.0.0.1:8080/VirtualHostBase/https/$server_name:443/some/path/VirtualHostRoot;
}

Instead use a combination of rewrite and proxy_pass:

location / {
  rewrite ^(.*)$ /VirtualHostBase/https/$server_name:443/some/path/VirtualHostRoot$1 break;
  proxy_pass   http://127.0.0.1:8080;
}

http://wiki.nginx.org/HttpProxyModule

分享到:
评论

相关推荐

    nginx location中多个if里面proxy_pass的方法

    在本文中,我们将深入探讨`location`指令的匹配机制以及在多个`if`语句中使用`proxy_pass`的方法。 首先,了解`location`的匹配指令: 1. `~`:表示执行一个正则匹配,区分大小写。 2. `~*`:表示执行一个正则匹配...

    nginx中location中关于proxy_pass和rewrite的应用.rar

    在`location`块中,`proxy_pass`和`rewrite`可以一起使用,先执行`rewrite`,然后转发给`proxy_pass`。这种组合使得Nginx能够根据重写后的URL找到正确的上游服务器,并处理请求。例如: ``` location /api { ...

    nginx proxy_pass指令’/’使用注意事项

    1. proxy_pass配置说明 不带/ 代码如下: location /test/ { proxy_pass http://t6:8300;  } 带/ 代码如下: location /test/  {   proxy_pass http://t6:8300/;   } 上面两种配置,区别只在于proxy_pass...

    Nginx服务器的反向代理proxy_pass配置方法讲解

    Nginx的配置还是比较简单的,如: location ~ /* { proxy_pass http://127.0.0.1:8008; } 或者可以 location / { proxy_pass http://127.0.0.1:8008; } Apache2的反向代理的配置是: ProxyPass /ysz/ ...

    nginx 反向代理之 proxy_pass的实现

    格式很简单: proxy_pass URL; 其中URL包含:传输协议(http://, https://等)、主机名(域名或者IP:PORT)、uri。 示例如下: proxy_pass http://www.xxx.com/; proxy_pass http://192.168.200.101:8080/uri; ...

    Nginx正向代理http和https.md

    proxy_temp_path /var/lib/nginx/tmp/proxy; server { listen 8080; server_name proxy.example.com; location / { proxy_pass http://192.168.252.247:80; proxy_set_header Host $host; proxy_set_...

    ngx_http_proxy_connect_module.zip

    在这个配置中,Nginx监听8080端口,当接收到CONNECT请求时,会尝试连接到配置的`$proxy_host:$proxy_port`。 使用该模块需要注意一些安全问题,因为透明代理可能被滥用为攻击跳板或绕过防火墙策略。为了安全起见,...

    nginx_tcp_proxy_module-master

    **Nginx TCP Proxy Module详解** Nginx作为一个流行的高性能HTTP和反向代理服务器,通常被用于处理HTTP和HTTPS协议的请求。然而,通过引入`nginx_tcp_proxy_module`,Nginx的功能得以扩展,能够处理TCP...

    nginx静态文件缓存的解决方案1

    ### 第三步:配置 proxy_pass 跳转的 location 中的静态文件路径 确保 Nginx 知道静态文件的存储位置,可以在相应 `location` 中使用 `root` 指令: ```nginx location ~ .*\.(html)$ { default_type 'text/html'...

    nginx配置文件中斜杠/的6种含义

    以下是`proxy_pass`指令中斜杠的不同含义,以及不写斜杠的情况: 1. **不包含斜杠**:当`proxy_pass`后面不带斜杠时,例如`proxy_pass http://backend;`,Nginx会将请求的URI与代理服务器的URL进行拼接。这意味着...

    Nginx反向代理proxy_cache_path directive is not allowed错误解决方法

    nginx: [emerg] “proxy_cache_path” directive is not allowed here in /etc/nginx/conf.d/default.conf:29 提示意思“proxy_cache_path指令不被允许”,在官网上查找了相关说明,也没有发现问题,最后看应用范围...

    Nginx之proxy_redirect使用详解

    其中,“default”模式下,Nginx会自动根据location和proxy_pass指令中的参数设置,来决定Location重定向的目标地址。而当设置为“off”时,则不进行重定向的修改。最后一种模式“redirect replacement”需要手动...

    nginx_tcp_proxy_module-master.zip

    nginx_tcp_proxy_module-master.zip

    ngixn正向https代理模块(透明代理)

    然后,在Nginx的配置文件中启用该模块,配置代理规则,如设置监听端口、指定目标服务器等。 3. 配置示例: ``` http { upstream baidu { server www.baidu.com; } server { listen 8443 ssl; ssl_...

    nginx系列(十)nginx缓存代理proxy_cacahe和CDN实现的原理

    Nginx可以作为一个轻量级的CDN解决方案,通过配置多个服务器块,将静态资源指向不同的存储位置或CDN服务。这涉及到Nginx的负载均衡、反向代理等功能。 3. **Nginx配置CDN**:在Nginx配置文件nginx.conf中,需要创建...

    使用nginx作为http/https正向代理ipm包,包含ngx_http_proxy_connect_module 模块,第三方图片代理,带有缓存

    使用nginx作为http/https正向代理ipm包,包含ngx_http_proxy_connect_module 模块,附带了第三方图片代理配置,带有缓存,可直接做图片服务器 下载后执行:rpm -ivh nginx-1.12.2-1.el7_4.ngx.x86_64.rpm 打包教程:...

Global site tag (gtag.js) - Google Analytics