Skip to content
This repository has been archived by the owner on Dec 22, 2024. It is now read-only.

Commit

Permalink
添加“理论基础”,附加其它优化
Browse files Browse the repository at this point in the history
  • Loading branch information
bddjr committed Jan 23, 2024
1 parent 34df0ea commit d7fd10b
Show file tree
Hide file tree
Showing 11 changed files with 110 additions and 12 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> ***简体中文***
> [English](english/README.md)
Expand All @@ -9,8 +9,9 @@
> [为同一主机的443端口配置HTTPS反向代理](为同一主机的443端口配置HTTPS反向代理.md)
> [配置HTTPS反向代理](配置HTTPS反向代理.md)
> [配置HTTP反向代理且合并端口](配置HTTP反向代理且合并端口.md)
>
> [理论基础](理论基础.md)
>
> ***
> <a href="https://proxyformcsm.bddjr.com/generator.html" target="_blank">配置文件的主要参数改起来有些麻烦?试试这款生成器吧!</a>
***
Expand All @@ -32,7 +33,7 @@ https://proxyformcsm.bddjr.com
```

***
其它文档请参考MCSM官方文档
MCSManager官方文档
<https://docs.mcsmanager.com/#/zh-cn/>

***
Expand Down
2 changes: 1 addition & 1 deletion english/443.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> [简体中文](../为同一主机的443端口配置HTTPS反向代理.md)
> ***English***
Expand Down
2 changes: 1 addition & 1 deletion english/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> [简体中文](../README.md)
> ***English***
Expand Down
2 changes: 1 addition & 1 deletion english/http-merge-ports.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> [简体中文](../配置HTTP反向代理且合并端口.md)
> ***English***
Expand Down
2 changes: 1 addition & 1 deletion english/https-merge-ports.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> [简体中文](../配置HTTPS反向代理且合并端口.md)
> ***English***
Expand Down
2 changes: 1 addition & 1 deletion english/https.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> [简体中文](../配置HTTPS反向代理.md)
> ***English***
Expand Down
2 changes: 1 addition & 1 deletion 为同一主机的443端口配置HTTPS反向代理.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> ***简体中文***
> [English](english/443.md)
Expand Down
97 changes: 97 additions & 0 deletions 理论基础.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
[<=点此返回README](README.md)

***
# 理论基础
> 所有相关的文章都基于理论基础。如果直接按照文章里的方式操作是没问题的,但一些特殊场景不能完全按照文章里的操作,因此需要自行基于一些理论进行修改。
> 本文的“Web端”指Web后端,“浏览器”指前端。
> 本文**不是**MCSManager官方开发人员写的。
***
## 连接Daemon
### 1. 浏览器 → Web端 → Daemon端
浏览器检查Daemon在线状态、获取Daemon的所有实例、管理Daemon的文件、修改Daemon的文件等绝大多数操作都会由Web端代理。



### 2. 浏览器 → Daemon端
连接实例终端、直接下载或直接上传文件,对应以下路径开头
> /socket.io/
> /upload/
> /download/
如果节点地址不填协议头,那么浏览器自动使用连接Web端时的协议(http对应ws,https对应wss)。
如果节点地址填了协议头,那么浏览器会使用填写的协议头。
如果节点地址去除协议头后,以 `localhost``127.0.0.` 开头,则浏览器会将域名替换成连接Web端时使用的域名。[[参考mcsm9的前端相关源码]](https://github.com/MCSManager/UI/blob/master/src/app/service/protocol.js#L131)
例如以下场景

1. Web使用`http://example.com:12333`
Daemon填写域名 `localhost` 端口 `12444`
那么浏览器会使用 `ws://example.com:12444``http://example.com:12444` 连接Daemon。

1. Web使用`https://example.com:12333`
Daemon填写域名 `localhost` 端口 `12444`
那么浏览器会使用 `wss://example.com:12444``https://example.com:12444` 连接Daemon。

1. Web使用`https://example.com:12333`
Daemon填写域名 `ws://localhost` 端口 `12444`
那么浏览器会使用 `ws://example.com:12444``http://example.com:12444` 连接Daemon,
**然后因为浏览器阻止https页面使用http请求资源,所以连接失败**

1. Web使用`https://example.com:12333`
Daemon填写域名 `wss://mcsmdaemon.example.com` 端口 `12444`
那么浏览器会使用 `wss://mcsmdaemon.example.com:12444``https://mcsmdaemon.example.com:12444` 连接Daemon。



### 3. Web端 → Daemon端
Web端会通过 `/socket.io/` 路径的开头连接Daemon,代理大多数操作。

修改nginx配置的Daemon端localhost部分的location,然后重载nginx,然后让Web端重新连接Daemon端,会发现一切操作正常进行,验证了上述理论。
```nginx
server {
# Daemon 端代理后localhost访问HTTP协议端口(可用多个listen监听多个端口)
```
```nginx
# 开始反向代理
# 代理Daemon端
location =/socket.io/ {
```

如果节点地址不填协议头,那么Web端自动使用ws协议。
如果节点地址填了协议头,那么Web端会使用填写的协议头。
例如以下场景

1. Daemon填写域名 `localhost` 端口 `12444`
那么Web端会使用 `ws://localhost:12444` 连接Daemon。

2. Daemon填写域名 `ws://localhost` 端口 `12444`
那么Web端会使用 `ws://localhost:12444` 连接Daemon。

3. Daemon填写域名 `wss://mcsmdaemon.example.com` 端口 `12444`
那么Web端会使用 `wss://mcsmdaemon.example.com:12444` 连接Daemon。



***
## 非常感谢您能阅读我写的教程,希望对你有帮助!
有错误的内容或改进的建议?或者没弄懂怎么配置?[点此编辑并提交issue](../../issues/new)

### 想要分享该文档?
[Gitee 仓库(中国内地访问稳定):](https://gitee.com/bddjr/nginx-proxy-docs-for-mcsm/blob/master/%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.md)
```
https://gitee.com/bddjr/nginx-proxy-docs-for-mcsm/blob/master/%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.md
```
[Github 仓库:](https://github.com/bddjr/nginx-proxy-docs-for-mcsm/blob/master/%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.md)
```
https://github.com/bddjr/nginx-proxy-docs-for-mcsm/blob/master/%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.md
```
[Github Page + Cloudflare CDN 网页:](https://proxyformcsm.bddjr.com/%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html)
```
https://proxyformcsm.bddjr.com/%E7%90%86%E8%AE%BA%E5%9F%BA%E7%A1%80.html
```

***
[<=点此返回README](README.md)

> 源码仓库:<a href="https://github.com/bddjr/nginx-proxy-docs-for-mcsm" target="_blank">nginx-proxy-docs-for-mcsm</a><br/>
> Made by <a href="https://bddjr.cn" target="_blank" rel="noopener">bddjr</a>
2 changes: 1 addition & 1 deletion 配置HTTPS反向代理.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> ***简体中文***
> [English](english/https.md)
Expand Down
2 changes: 1 addition & 1 deletion 配置HTTPS反向代理且合并端口.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> ***简体中文***
> [English](english/https-merge-ports.md)
Expand Down
2 changes: 1 addition & 1 deletion 配置HTTP反向代理且合并端口.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Language
Language
> ***简体中文***
> [English](english/http-merge-ports.md)
Expand Down

0 comments on commit d7fd10b

Please sign in to comment.