NginxMap转换到Apache2

llmtgqce  于 2023-11-17  发布在  Nginx
关注(0)|答案(1)|浏览(182)

我正在努力寻找答案,有没有可能将下面这样的NginxMap转换为Apache2(2.4)等价物?

  1. server {
  2. [...]
  3. location ~* ^(/_matrix|/_synapse) {
  4. proxy_pass http://$matrix_worker_upstream$request_uri;
  5. proxy_set_header X-Forwarded-For $remote_addr;
  6. proxy_set_header X-Forwarded-Proto $scheme;
  7. proxy_set_header Host $host;
  8. client_max_body_size 50M;
  9. proxy_http_version 1.1;
  10. }
  11. [...]
  12. }
  13. upstream synapse {
  14. server 127.0.0.1:8008;
  15. }
  16. upstream generic-worker {
  17. ip_hash;
  18. server 127.0.0.1:8008;
  19. server 127.0.0.1:8081;
  20. }
  21. upstream media_repository {
  22. server 127.0.0.1:8085;
  23. }
  24. map $uri $matrix_worker_upstream {
  25. default synapse;
  26. ~^/_matrix/client/(r0|v3)/sync$ generic-worker;
  27. ~^/_matrix/client/(api/v1|r0|v3)/events$ generic-worker;
  28. ~^/_matrix/client/(api/v1|r0|v3)/initialSync$ generic-worker;
  29. ~^/_matrix/client/(api/v1|r0|v3)/rooms/[^/]+/initialSync$ generic-worker;
  30. [...]
  31. }

字符串
如果我理解的好,上游可以转换为代理均衡器这样?

  1. <Proxy balancer://generic-worker>
  2. BalancerMember http://127.0.0.1:8080
  3. BalancerMember http://127.0.0.1:8081
  4. </Proxy>


但我不知道如何转换Map部分?(有负载的网址内Map)
这是一个Synapse(Matrix)与worker的配置。为什么是Apache2?这是为了避免Shibboleth与Matrix的额外配置。

8oomwypt

8oomwypt1#

这是我得到的,似乎工作,即使其他错误抬头.

  1. RequestHeader set X-Forwarded-For "%{REMOTE_ADDR}e"
  2. RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}
  3. RequestHeader set Host expr=%{HTTP_HOST}
  4. <Proxy balancer://generic_worker>
  5. BalancerMember http://127.0.0.1:8008
  6. BalancerMember http://127.0.0.1:8081
  7. </Proxy>
  8. <Proxy balancer://media_repository>
  9. BalancerMember http://127.0.0.1:8085
  10. </Proxy>
  11. ProxyPassMatch /_matrix/client/(r0|v3)/sync(.*) balancer://generic_worker/_matrix/client/$1/sync$2 nocanon
  12. ProxyPassReverse /_matrix/client/(r0|v3)/sync(.*) balancer://generic_worker/_matrix/client/$1/sync$2
  13. ProxyPassMatch /_matrix/client/(api/v1|r0|v3)/events(.*) balancer://generic_worker/_matrix/client/$1/events$2 nocanon
  14. ProxyPassReverse /_matrix/client/(api/v1|r0|v3)/events(.*) balancer://generic_worker/_matrix/client/$1/events$2
  15. ProxyPassMatch /_matrix/client/(api/v1|r0|v3)/initialSync(.*) balancer://generic_worker/_matrix/client/$1/initialSync$2 nocanon
  16. ProxyPassReverse /_matrix/client/(api/v1|r0|v3)/initialSync(.*) balancer://generic_worker/_matrix/client/$1/initialSync$2
  17. ProxyPassMatch /_matrix/client/(api/v1|r0|v3)/rooms/(.*)/initialSync(.*) balancer://generic_worker/_matrix/client/$1/rooms/$2/initialSync$3 nocanon
  18. ProxyPassReverse /_matrix/client/(api/v1|r0|v3)/rooms/(.*)/initialSync(.*) balancer://generic_worker/_matrix/client/$1/rooms/$2/initialSync$3
  19. [...]
  20. # defaut master
  21. ProxyPassMatch /_matrix/(.*) http://127.0.0.1:8008/_matrix/$1 nocanon
  22. ProxyPassReverse /_matrix/(.*) http://127.0.0.1:8008/_matrix/$1
  23. ProxyPass /_synapse/client(.*) http://127.0.0.1:8008/_synapse/client$1 nocanon
  24. ProxyPassReverse /_synapse/client(.*) http://127.0.0.1:8008/_synapse/client$1

字符串
上游转换为代理平衡器,但每个Map元素都转换为代理通行规则。应该有一种方法来缩短这一点,虽然...
另外,Apache mods需要启用:

  1. a2enmod headers
  2. a2enmod proxy
  3. a2enmod proxy_http
  4. a2enmod proxy_balancer
  5. a2enmod lbmethod_byrequests

展开查看全部

相关问题