lus / pasty

pasty is a fast and lightweight code pasting server
https://pasty.lus.pm
MIT License
201 stars 29 forks source link

Pasty behind Reverse Proxy as Subpath #46

Open GAS85 opened 2 years ago

GAS85 commented 2 years ago

Hey, cool Product!

I try to run it as Sub-path on Apache2 Server e.g. https://FQDN/pasty/ with few rewrite rules, but not really successful.

  1. I use docker compose
    version: "3.6"
    services:
    pasty:
    image: ghcr.io/lus/pasty:latest
    container_name: pasty
    restart: unless-stopped
    environment:
      - PASTY_AUTODELETE="true"
      - PASTY_AUTODELETE_LIFETIME="336h"
      - PASTY_AUTODELETE_TASK_INTERVAL="24h"
    ports:
      - "9016:8080"
  2. Now it works on my localhost:9016
  3. I see that there a 2 endpoints, webUI and api calls, so I add Apache2 Rewrite rules:
    
    #Pasty
    <Location /api/v2/>
        RewriteEngine  on
        RewriteRule /api/v2/(.*) http://localhost:9016/api/v2/$1 [P,L]
        ProxyPreserveHost On
        ProxyPass http://localhost:9016/api/v2/ retry=0 connectiontimeout=5 timeout=30 keepalive=on
        ProxyPassReverse http://localhost:9016/api/v2/
        RequestHeader set Connection ""
    </Location>

Redirect 301 "/pasty" "/pasty/" <Location /pasty/> ProxyPreserveHost On ProxyPass http://localhost:9016/ retry=0 connectiontimeout=5 timeout=30 keepalive=on ProxyPassReverse http://localhost:9016/ RequestHeader set Connection ""


4. Not really works:(((
How to expose this app as Subpath?
lus commented 2 years ago

Hello! I am not familiar with Apache2 and its configuration, but based on your description I can imagine one problem. The frontend currently calls the API on the main hostname (https://github.com/lus/pasty/blob/efe0ec7556a936c5aee0abd9d60c347c8db64f4d/web/assets/js/modules/api.js#L1) and not relative to the path. If pasty runs on https://host.example/pasty for example, it will call https://host.example/api/v2 rather than https://host.example/pasty/api/v2. This is bad behaviour and will be fixed. If this is not your problem, please try to access pasty with your browser's developer mode network tab open and try to determine any network errors.

GAS85 commented 2 years ago

I try to add rule for https://FQDN/api/v2 endpoint, but not as for other tools - it causes redirect loop from https://FQDN/api/v2/pastes to https://FQDN/api/v2/api/v2/pastes. Funny that https://FQDN/api/v2/info works fine.

Any Idea how to with ngnix?

gwolf2u commented 2 years ago

idea why not run on subdomain?

this is what I have for subdomain with nginx

server {
        listen 80;
        listen [::]:80;

        server_name paste.domain.tld www.paste.domain.tld;

        location / {
            proxy_pass http://127.0.0.1:8080;
        }
}
GAS85 commented 2 years ago

Hmmm. This is different requirement from this ticket and it works.

Any way issue is in endpoint as mentioned above: https://FQDN/api/v2/info works fine āœ”ļø https://FQDN/api/v2/pastes does not āŒ

I would also prefer if possibility to configure sub-path via container variable could be add here, so that all calls goes to https://FQDN/SUB_PATH/api/v2 and https://FQDN/SUB_PATH/ for Frontend šŸ˜„

matnakal77 commented 2 years ago

Hey, cool Product!

I try to run it as Sub-path on Apache2 Server e.g. https://FQDN/pasty/ with few rewrite rules, but not really successful.

  1. I use docker compose
    version: "3.6"
    services:
    pasty:
    image: ghcr.io/lus/pasty:latest
    container_name: pasty
    restart: unless-stopped
    environment:
      - PASTY_AUTODELETE="true"
      - PASTY_AUTODELETE_LIFETIME="336h"
      - PASTY_AUTODELETE_TASK_INTERVAL="24h"
    ports:
      - "9016:8080"
  2. Now it works on my localhost:9016
  3. I see that there a 2 endpoints, webUI and api calls, so I add Apache2 Rewrite rules:
    
    #Pasty
    <Location /api/v2/>
      RewriteEngine  on
      RewriteRule /api/v2/(.*) http://localhost:9016/api/v2/$1 [P,L]
      ProxyPreserveHost On
      ProxyPass http://localhost:9016/api/v2/ retry=0 connectiontimeout=5 timeout=30 keepalive=on
      ProxyPassReverse http://localhost:9016/api/v2/
      RequestHeader set Connection ""
    </Location>

Redirect 301 "/pasty" "/pasty/" <Location /pasty/> ProxyPreserveHost On ProxyPass http://localhost:9016/ retry=0 connectiontimeout=5 timeout=30 keepalive=on ProxyPassReverse http://localhost:9016/ RequestHeader set Connection ""


4. Not really works:(((
How to expose this app as Subpath?
Pkg install