Skip to content

Commit a2f1fef

Browse files
committed
proxy_pass 代理的URL总结
1 parent a76986b commit a2f1fef

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

README.md

+44-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@
540540
- [x] [nginx变量使用方法详解笔记(3)](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx/nginx-2-config.md)
541541
+ Nginx指令执行顺序
542542
- [x] [Nginx指令执行命令(01)](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx-Develop/command-order-01.md)
543-
#### <a name="Nginx_Web2_knowledge"/> 第二章 安装部署
543+
#### <a name="Nginx_Web2_knowledge"/> 第二章 安装部署
544+
+ 启动错误:`Nginx [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)`,执行:`sudo fuser -k 80/tcp`
544545
+ [基于域名、IP的虚拟主机配置](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx/Nginx-Web/Nginx-2-4-all-config.md)
545546
+ [完整、标准配置实际示列](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx/Nginx-Web/Nginx-2-4-basic-config.md)
546547
+ [日志文件配置与切割](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx/Nginx-Web/Nginx-2-4-log-cut.md)
@@ -759,6 +760,48 @@
759760
+ TCP负载均衡
760761
- [x] [Module ngx_stream_core_module](http://nginx.org/en/docs/stream/ngx_stream_core_module.html#stream)
761762
- [x] [负载均衡](https://github.com/Tinywan/Lua-Nginx-Redis/blob/master/Nginx/Nginx-Web/Nginx-8-tcp-Proxy.md)
763+
+ proxy_pass 代理的URL总结
764+
+nginx中配置proxy_pass时,当在后面的url加上了/,相当于是绝对根路径,则nginx不会把location中匹配的路径部分代理走;如果没有/,则会把匹配的路径部分也给代理走。
765+
+url中以/wap/开头的请求转发到后台对应的某台server上,注意最后的?$args,表明把原始url最后的get参数也给代理到后台
766+
```bash
767+
location ~* /wap/(\d+)/(.+)
768+
{
769+
proxy_pass http://mx$1.test.com:6601/$2?$args;
770+
}
771+
```
772+
+ 第一种配置,访问:`http://127.0.0.1/proxy/index.html` 会被代理到:`http://127.0.0.1:8000/index.html`
773+
```bash
774+
location /proxy/ {
775+
proxy_pass http://127.0.0.1:8000/;
776+
}
777+
```
778+
+ 第二种配置,访问:`http://127.0.0.1/proxy/index.html` 会被代理到:`http://127.0.0.1:8000/proxy/index.html`
779+
```bash
780+
location /proxy/ {
781+
proxy_pass http://127.0.0.1:8000;
782+
}
783+
```
784+
+ 第三种配置,访问:`http://127.0.0.1/proxy/index.html` 会被代理到:`http://127.0.0.1:8000/video/index.html`
785+
```bash
786+
location /proxy/ {
787+
proxy_pass http://127.0.0.1:8000/video/;
788+
}
789+
```
790+
+ 第四种配置,访问:`http://127.0.0.1/proxy/index.html` 会被代理到:`http://127.0.0.1:8000/videoindex.html`
791+
```bash
792+
location /proxy/ {
793+
proxy_pass http://127.0.0.1:8000/video;
794+
}
795+
```
796+
+ location 直接访问:
797+
+ 以下配置,当访问:`http://127.0.0.1:8000/proxy/index.html` 会被匹配到:`/usr/local/nginx/html/proxy/index.html`
798+
```bash
799+
location /proxy/ {
800+
root /usr/local/nginx/html;
801+
index index.html index.htm;
802+
}
803+
```
804+
762805
## <a name="Nginx_Web8_knowledge"/> 第八章 缓存机制
763806
+ 测试一
764807
## <a name="Nginx_Web9_knowledge"/> 第九章 Nginx初探1

0 commit comments

Comments
 (0)