一、location匹配路径末尾没有 /

location /sta
{
proxy_pass http://192.168.1.1/sta;
}

外面访问:http://外网IP/sta/sta1.html
相当于访问:http://192.168.1.1/sta/sta1.html

二、location匹配路径末尾有 /
此时proxy_pass后面的路径需要分为以下四种情况讨论:

(1)proxy_pass后面的路径只有域名且最后没有 /
location /sta/
{
proxy_pass http://192.168.1.1;
}

外面访问:http://外网IP/sta/sta1.html
相当于访问:http://192.168.1.1/sta/sta1.html

(2)proxy_pass后面的路径只有域名同时最后有 /
location /sta/
{
proxy_pass http://192.168.1.1/;
}

外面访问:http://外网IP/sta/sta1.html
相当于访问:http://192.168.1.1/sta1.html

(3)proxy_pass后面的路径还有其他路径但是最后没有 /:

location /sta/
{
proxy_pass http://192.168.1.1/abc;
}

外面访问:http://外网IP/sta/sta1.html
相当于访问:http://192.168.1.1/abcsta1.html

(4)proxy_pass后面的路径还有其他路径同时最后有 /:
location /sta/
{
proxy_pass http://192.168.1.1/abc/;
}
外面访问:http://外网IP/sta/sta1.html
相当于访问:http://192.168.1.1/abc/sta1.html

nginx的proxy_pass路径转发规则最后带/问题的更多相关文章

  1. nginx的proxy_pass路径转发规则浅析(末尾/问题)

    源地址 : https://www.zifangsky.cn/917.html 一 location匹配路径末尾没有 / 此时proxy_pass后面的路径必须拼接location的路径:   1 2 ...

  2. Nginx配置proxy_pass转发的/路径问题

    Nginx配置proxy_pass转发的/路径问题 在nginx中配置proxy_pass时,如果是按照^~匹配路径时,要注意proxy_pass后的url最后的/,当加上了/,相当于是绝对根路径,则 ...

  3. 用haproxy实现nginx的proxy_pass转发功能

    公司的网站有个需求,主站点上有两个URL,没有在本地nginx上配置,而是在另一台主机的nginx上配置的站点.如果使用nginx作为反向代理,可以使用proxy_pass指令转发对这两个URL的请求 ...

  4. Nginx location 和 proxy_pass路径配置详解

    目录 一.Nginx location 基本配置 1.1.Nginx 配置文件 1.2 .Python 脚本 二.测试 2.1.测试 location 末尾存在 / 和 proxy_pass末尾存在 ...

  5. (转)nginx做转发时,带'_'的header内容丢失

    原本在测试环境测试通过的APP,今天准备切到线上环境做最后测试,结果发现了错误.查看日志发现是APP端发送的http请求中的header内容丢失了.那么代码没有改动,怎么平白无故会丢失头信息? 于是想 ...

  6. Nginx配置location及rewrite规则

    Nginx配置location及rewrite规则 示例: location  = / {   # 精确匹配 / ,主机名后面不能带任何字符串   [ configuration A ] } loca ...

  7. Nginx配置proxy_pass

    nginx配置proxy_pass,需要注意转发的路径配置 1.location /test/ { proxy_pass http://t6:8300; } 2.location /test/ { p ...

  8. nginx 之 proxy_pass

    nginx中有两个模块都有proxy_pass指令 ngx_http_proxy_module的proxy_pass 语法: proxy_pass URL; 场景: location, if in l ...

  9. Nginx 常用全局变量 及Rewrite规则详解

    每次都很容易忘记Nginx的变量,下面列出来了一些常用 $remote_addr //获取客户端ip $binary_remote_addr //客户端ip(二进制) $remote_port //客 ...

随机推荐

  1. fiddler抓取用tomcat来部署的项目接口请求包

    Fiddler 是以代理web服务器的形式工作的,它使用代理地址:127.0.0.1,端口:8888. 当Fiddler退出的时候它会自动注销, 这样就不会影响别的程序.关于fiddler这个工具的使 ...

  2. AWK入门

    AWK类型    AWK:源于AT&T实验室的AWK    NAWK:AWK的升级版    GAWK:GNU AWK,兼容AWK和NAWK    程序结构    BEGIN语句块,可选     ...

  3. Guess Number Game

    We are playing the Guess Game. The game is as follows: I pick a number from 1 to n. You have to gues ...

  4. 关于win10安装javaJDK时遇到的问题

    昨天晚上装了一下javaJDK1.8,在安装成功并且按照教程设置完环境变量之后进入了cmd界面,输入java,java -version都正常显示,但是输入javac却报错:javac不是内部或外部命 ...

  5. vue 创建项目

    先安装node.js环境 #先安装npm 阿里镜像 (之后cnpm 下载组件快速) npm install -g cnpm --registry=https://registry.npm.taobao ...

  6. python面向对象基本概念(OOP)

    面向对象(OOP)基本概念 面向对象编程 —— Object Oriented Programming 简写 OOP 目标 了解 面向对象 基本概念 01. 面向对象基本概念 我们之前学习的编程方式就 ...

  7. angular2在ts中使用transform转换时间格式

    摘要:在angular1中我们可以在控制器中像下面那样使用filter: $filter('date')(myDate, 'yyyy-MM-dd'); 但是如何在angular2中在ts中使用自定义p ...

  8. JS类小功能

    工作中,总是要处理一些前端的小功能.都是网上搜的JS脚本 <script> //防止页面后退 history.pushState(null, null, document.URL); wi ...

  9. s21day10 python笔记

    s21day10 python笔记 一.函数补充 1.1 参数 基本参数知识 def get_list_date(aaa): #aaa:形式参数(形参) 任意个数 v = [11,22,33,44] ...

  10. 实现两个矩阵相乘的C语言程序

    程序功能:实现两个矩阵相乘的C语言程序,并将其输出 代码如下: #include "stdafx.h" #include "windows.h" void Mu ...