pasty icon indicating copy to clipboard operation
pasty copied to clipboard

Pasty behind Reverse Proxy as Subpath

Open GAS85 opened this issue 2 years ago • 5 comments

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"
  1. Now it works on my localhost:9016
  2. 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 ""
	</Location>
  1. Not really works:((( How to expose this app as Subpath?

GAS85 avatar Jun 09 '22 11:06 GAS85

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.

lus avatar Jun 09 '22 11:06 lus

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?

GAS85 avatar Jun 09 '22 14:06 GAS85

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;
        }
}

gwolf2u avatar Jun 12 '22 12:06 gwolf2u

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 😄

GAS85 avatar Jun 29 '22 09:06 GAS85

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"
  1. Now it works on my localhost:9016
  2. 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 ""
	</Location>
  1. Not really works:((( How to expose this app as Subpath? Pkg install

matnakal77 avatar Jul 04 '22 17:07 matnakal77