Docker Swarm上的NGINX可以在同一个端口上提供多个应用程序


不丶离
2025-03-17 08:43:59 (3天前)


我知道已经提出了类似的问题,但我找到的主题,文章和博客都没有让我解决我的问题。让我在这里非常坦率和具体:

1.我有什么:……

2 条回复
  1. 0# 哦豁 | 2019-08-31 10-32



    我无法帮助Jupyter和Spark,但希望这个答案对你有帮助。



    如果您计划在反向代理之后放置一些内容,则应该验证它是否可以在反向代理之后工作,如您所述。




    127.0.0.1/jupyter/tree,它将我重定向到127.0.0.1/tree




    因为对于Jupyter root来说

    /

    不是

    /jupyter

    ,所以你需要在配置中找到如何更改它,作为Grafana的一个例子。



    1.   # The full public facing url you use in browser, used for redirects and emails
    2. If you use reverse proxy and sub path specify full url (with sub path)

      root_url = https://example.com/grafana

    3. </code>


    NGINX配置可以简化,请看这个例子:




    nginx配置
    </强>



    1.   # /etc/nginx/conf.d/default.conf
    2. server {
      listen 80 default_server;

    3. location = /echo1 {
    4.     rewrite ^ /echo1/ permanent;
    5. }
    6. location = /echo2 {
    7.     rewrite ^ /echo2/ permanent;
    8. }
    9. location /echo1/ {
    10.     proxy_pass        http://echo1:8000/;
    11. }
    12. location /echo2/ {
    13.     proxy_pass        http://echo2:8000/;
    14. }
    15. location / {
    16.     return 404;
    17. }
    18. }

    19. </code>



    泊坞窗,撰写
    </强>




    1. version: 3.2

    2. services:
      nginx:
      image: ddmitrii/nginx-sample:echo2
      ports:

    3.         - '80:80'
    4. echo1:
    5.     image: ddmitrii/echo
    6.     command: --url --id echo1
    7. echo2:
    8.     image: ddmitrii/echo
    9.     command: --url --id echo2
    10. </code>



    测试
    </强>




    1. $ curl -L localhost/echo1/
      echo1 GET /
      $ curl -L localhost/echo2
      echo2 GET /

    2. </code>



    备注
    </强>



    变量




    1. proxy_set_header Host $http_host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header X-Forwarded-Proto $scheme;

    2. </code>


    只有在需要软件时才应该放置到位,这些名称就像

    X-Real-IP

    可以是不同的,您需要用软性要求进行验证。



    你不需要




    重写^ / rstudio(/.*)$ 1休息;




    因为nginx会自动遵循正确的规则,所以你需要为路径重写规则

    /path

    ,切断

    path

    ,所以它会

    /

    (或者是其他东西)




    旋转变压器127.0.0.11有效= 5s;




    因为你使用localhost




    设置$ upstream_endpoint jupyter:8888;




    因为proxy_pass。




    proxy_redirect $ scheme:// $ upstream_endpoint / $ scheme:// $ host / jupyter /;




    因为proxy_pass。



    其他一切看起来都不错


登录 后才能参与评论