Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pasty behind Reverse Proxy as Subpath #46

Open
GAS85 opened this issue Jun 9, 2022 · 5 comments
Open

Pasty behind Reverse Proxy as Subpath #46

GAS85 opened this issue Jun 9, 2022 · 5 comments

Comments

@GAS85
Copy link

GAS85 commented Jun 9, 2022

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?
@lus
Copy link
Owner

lus commented Jun 9, 2022

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 (

const API_BASE_URL = location.protocol + "//" + location.host + "/api/v2";
) 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
Copy link
Author

GAS85 commented Jun 9, 2022

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
Copy link
Contributor

gwolf2u commented Jun 12, 2022

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
Copy link
Author

GAS85 commented Jun 29, 2022

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants