plantuml / plantuml-server

PlantUML Online Server
https://plantuml.com/
GNU General Public License v3.0
1.6k stars 463 forks source link

NGINX config to server static diagrams for inclusion into others #202

Closed CyberSeppi closed 1 year ago

CyberSeppi commented 2 years ago

Hi there,

I set up an nginx which should serve static files (diagrams in my case) that can be included into others like

!include https://......

The thing is, that it doesn´t work. It works with, e.g https://raw.githubusercontent.com/plantuml-stdlib/C4-PlantUML/master/C4_Container.puml

The difference are the META of the http response, and that favicon.ico, which I had to "dummy" (just return 200 without content)

image

Can you tell me how to set up the response to make it working ?

Thanks and Greetings,

Julian

HeinrichAD commented 1 year ago

If I have to guess, I think the problem is that an !include http://localhost or !include http://plantuml-server, at the time of fetching the diagram, points to itself (PlantUML Server) and not to the Nginx server.


The following situation is working for me:

I modified the Nginx reverse proxy example with defined location directive (different context path).

What I did:

  1. create the following test diagram nginx-contextpath/diagrams/test.puml:
    Alice -> Bob : "I am from another file"
  2. add the new folder inside the Nginx server as an additional docker volume:
        volumes:
          - ./nginx.conf:/etc/nginx/nginx.conf:ro
    +     - ./diagrams:/www/diagrams:ro
  3. tell Nginx (nginx.conf) to server (static) the newly added directory

    http {
    +    # OPTIONAL  (It work for me with and without it)
    +    types {
    +        text/plain   puml;
    +    }
    
        server {
            listen          80;
            server_name     localhost;
    +       root /www;
    
            # PlantUML
            location /plantuml/ {
                proxy_pass http://plantuml-server:8080/plantuml/;
            }
        }
    # ...
  4. try it
    1. start Nginx + PlantUML Server: docker compose up -d (see example README)
    2. go to: http://localhost/plantuml
    3. enter diagram code
      @startuml
      !include http://nginx/diagrams/test.puml
      Bob -> Alice : hello
      @enduml

      NOTE: I used !include http://nginx/diagrams/test.puml and not localhost! The reason is fairly simple, at the time when the PlantUML Server tries to fetch the diagram from localhost, localhost does not point to the Nginx server but to the PlantUML Server itself.

  5. see result image