Coder Social home page Coder Social logo

Comments (11)

pcolmer avatar pcolmer commented on June 16, 2024 1

@joachimmueller that's fine.

I've found another place in the YOURLS code that is making it hard, if not impossible, to use Apache to proxy YOURLS with a sub-path. I've submitted another PR for that situation:

YOURLS/YOURLS#2606

from images.

LeoColomb avatar LeoColomb commented on June 16, 2024

Thanks for your report @joachimmueller.

That said this is a very weird setup, and I'm pretty sure the issue is nothing with the YOURLS Docker image directly.
Did you try with another Docker image, let's say WordPress one?
If so, you must provide some Docker and/or Apache logs to go further.

from images.

joachimmueller avatar joachimmueller commented on June 16, 2024

WOW, that was an quick reply 👍

The setup is not that weird. I just have no control of the hosts sub domains and must use a path to access yourls. It's even one possible containerless setup: https://github.com/YOURLS/YOURLS/wiki/.htaccess.

I guess it would require to copy the source into a subdirectory by the docker-entrypoint.sh script.

Does anybody has this requirement as well (running docker-yourls behind a path)?

from images.

LeoColomb avatar LeoColomb commented on June 16, 2024

It's even one possible containerless setup

Hmm, that's not exactly the same case.
The setup described in the wiki is when you directly access a sub-directory.
Your setup is a sub-path shadowed by a proxy. In that case the complicated part is proxy' configuration written to perform the perfect rewrite (if even possible).

Are you sure it is possible? I.e. have you tested successfully with another docker image?

from images.

LeoColomb avatar LeoColomb commented on June 16, 2024

Closing for now, as it seems to be unrelated to docker-yourls specifically, but please don't hesitate to post below any new info or test results.

from images.

pcolmer avatar pcolmer commented on June 16, 2024

I've found one error in the underlying yourls code which prevents the Docker container from being proxied 100% successfully and I've raised a PR to fix it:

YOURLS/YOURLS#2604

@joachimmueller did you manage to get this working? I'm still hitting some issues that I'm digging into the yourls code to try and figure out what is going on.

from images.

joachimmueller avatar joachimmueller commented on June 16, 2024

We switched to a subdomain. Sorry, can't help at the moment.

from images.

pcolmer avatar pcolmer commented on June 16, 2024

I've got to a point where it doesn't seem to be easy to fix this problem.

Option 1: proxy from a path to a root-space container, e.g. ProxyPass /app/ http://localhost:8002/ in Apache and YOURLS_SITE set to the full parent path, e.g. http://test.example.com/app

With this approach, the UI all works but the shortlinks don't. The reason why the shortlinks don't work is because yourls in the container thinks it is working at the root of the URL so when yourls_get_request is called, it hits:

$uri = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

which results in $uri being set to test.example.com/test-link and not test.example.com/app/test-link so the loader fails.

Option 2. proxy from a path to the same path inside the container, e.g. ProxyPass /app/ http://localhost:8002/app/ in Apache and YOURLS_SITE set to the full parent path, e.g. http://test.example.com/app

With this approach, shortlinks work but the UI doesn't. The problem is that the .htaccess file triggers yourls-loader.php. The instructions for .htaccess (https://github.com/YOURLS/YOURLS/wiki/.htaccess) talk about if YOURLS is installed in a subdirectory, but that doesn't help with this scenario, where YOURLS itself is instead in the root directory but being proxied as if it were in a subdirectory.

So, the solution I've adopted is similar to YOURLS/YOURLS#2604 where I now reference YOURLS_SITE instead of relying on the host information passed via Apache. This turns out to be very similar to the allow-aliases plugin which means that, if you are using yourls in a Container, that plugin is no longer needed.

Fixed in YOURLS/YOURLS#2608.

from images.

pcolmer avatar pcolmer commented on June 16, 2024

With all of the fixes applied, an Apache configuration file like the following can be used:

<VirtualHost *:80>
    ProxyRequests           Off
    ProxyPreserveHost       Off
    ProxyPass               /yourls/   http://localhost:8002/ connectiontimeout=5 timeout=300
    ProxyPassReverse        /yourls/   http://localhost:8002/
</VirtualHost>

Note that YOURLS_SITE in the docker-compose.yml file must be set to the full hostname and path, e.g. http://test.example.com/yourls.

from images.

LeoColomb avatar LeoColomb commented on June 16, 2024

Thanks for this extensive review @pcolmer, very appreciated! 👍

from images.

Dherlou avatar Dherlou commented on June 16, 2024

If someone has trouble configuring this setup with an nginx instead of an Apache reverse proxy (hello to future-me in a few years), the following location snippet for the server configuration did the trick for me. Unfortunately, I already lost the source of the original snippet, where I copied most of it from.
yourls is the name of my container in the same network as the nginx reverse proxy and go is the path I am serving it under.

location /go/ {
        if ( $uri ~ ^\/go\/((admin|css|images|js)(\/?)(.*)|.*.(\.html|\.php)) ) {
            rewrite /go(/.*) $1 break;
        }
        proxy_pass http://yourls;
        proxy_redirect / /go/;
}

In case it matters, I have also defined the following proxy settings:

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

client_max_body_size 1024M;

proxy_redirect      off;
proxy_set_header    Host $host;
proxy_set_header    X-Real-IP $remote_addr;
proxy_set_header    X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header    X-Forwarded-Proto $scheme;
proxy_set_header    X-Forwarded-Host $server_name;
proxy_set_header    X-Forwarded-Port $server_port;
proxy_set_header    Upgrade $http_upgrade;
proxy_set_header    Connection "Upgrade";
proxy_read_timeout  3600;

from images.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.