Skip to content

Pasty behind Reverse Proxy as Subpath #46

Open

Description

@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?

Activity

  1. lus commented on Jun 9, 2022

    @lus
    Owner

    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.

  2. GAS85 commented on Jun 9, 2022

    @GAS85
    Author

    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?

  3. gwolf2u commented on Jun 12, 2022

    @gwolf2u
    Contributor

    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;
            }
    }
    
  4. GAS85 commented on Jun 29, 2022

    @GAS85
    Author

    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 😄

  5. matnakal77 commented on Jul 4, 2022

    @matnakal77

    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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions