-
Notifications
You must be signed in to change notification settings - Fork 2
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
Nginx configuration for the image proxy is not working #6
Comments
It looks like a problem with the Ngxin proxy configuration. I can connect directly to the API service from the server:
|
I have enabled the Nginx debug mode with:
And it seems Nginx is removing one slash in the redirection URL: 2023/12/14 16:53:39 [notice] 20#20: *1 "^/api/(.*)$" matches "/api/v1/proxy/image/https:/raw.githubusercontent.com/torrust/torrust-index/develop/docs/media/torrust_logo.png", client: 2.137.102.79, server: index.torrust-demo.com, request: "GET /api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png HTTP/2.0", host: "index.torrust-demo.com", referrer: "https://index.torrust-demo.com/torrent/443c7602b4fde83d1154d6d9da48808418b181b6/ubuntu-2304-desktop-amd64"
2023/12/14 16:53:39 [notice] 20#20: *1 rewritten data: "/v1/proxy/image/https:/raw.githubusercontent.com/torrust/torrust-index/develop/docs/media/torrust_logo.png", args: "", client: 2.137.102.79, server: index.torrust-demo.com, request: "GET /api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png HTTP/2.0", host: "index.torrust-demo.com", referrer: "https://index.torrust-demo.com/torrent/443c7602b4fde83d1154d6d9da48808418b181b6/ubuntu-2304-desktop-amd64"
2.137.102.79 - - [14/Dec/2023:16:53:39 +0000] "GET /api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png HTTP/2.0" 404 0 "https://index.torrust-demo.com/torrent/443c7602b4fde83d1154d6d9da48808418b181b6/ubuntu-2304-desktop-amd64" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36" "-" As you can see is using |
By enabling the option
It seems that now it's using this URL:
It adds two slashes but It's not working because this URL: does not work. hHe URL of the image has to be URL encoded in the PATH. |
It seems I have to change the Nginx config:
Because:
It seems I have to use the variable |
ChatGTP suggested to do this:
|
Relates to: torrust/torrust-index-gui#409 |
I've tried a lot of different configurations for Nginx but none of them have worked.
It seems that if you want to parse and modify the URI, Nginx decodes it. Some options like:
or
seems to work but I get this error:
|
I'm using this configuration to enable proxy:
image: nginx
container_name: proxy
restart: unless-stopped
networks:
- frontend_network
- backend_network
ports:
- "80:80"
- "443:443"
volumes:
- ./storage/proxy/webroot:/var/www/html
- ./storage/proxy/etc/nginx-conf:/etc/nginx/conf.d
- ./storage/certbot/etc:/etc/letsencrypt
- ./storage/certbot/lib:/var/lib/letsencrypt
- ./storage/dhparam:/etc/ssl/certs
command: [nginx-debug, '-g', 'daemon off;']
logging:
options:
max-size: "10m"
max-file: "10"
depends_on:
- index-gui
- index
- tracker |
I finally found a working configuration:
It works, but it has a potential problem. The
CUrrently, it's not a problem because URL are like this: We do not have any "query" in the image proxy URLs. |
We need to pass the original URL encoded URL: http://index.torrust-demo.com/api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png from the Nginx reverse proxy to the Index API image proxy. Otherwise we get a 404. The proxy was passing an URL like this: "/v1/proxy/image/https:/raw.githubusercontent.com/torrust/torrust-index/develop/docs/media/torrust_logo.png which is not valid because it containts unscaped chars. Not It's passing: "/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png" This solution is not passing the rest of the URL: query parameters. But we do not need them in the image proxy.
We need to pass the original URL encoded URL: http://index.torrust-demo.com/api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png from the Nginx reverse proxy to the Index API image proxy. Otherwise we get a 404. The proxy was passing an URL like this: "/v1/proxy/image/https:/raw.githubusercontent.com/torrust/torrust-index/develop/docs/media/torrust_logo.png which is not valid because it containts unscaped chars. Not It's passing: "/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png" This solution is not passing the rest of the URL: query parameters. But we do not need them in the image proxy.
3070c88 fix: [#6] pass encoded URL to image proxy (Jose Celano) Pull request description: We need to pass the original URL encoded URL: http://index.torrust-demo.com/api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png from the Nginx reverse proxy to the Index API image proxy. Otherwise we get a 404. The proxy was passing an URL like this: "/v1/proxy/image/https:/raw.githubusercontent.com/torrust/torrust-index/develop/docs/media/torrust_logo.png which is not valid because it containts unscaped chars. Not It's passing: "/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png" This solution is not passing the rest of the URL: query parameters. But we do not need them in the image proxy. Top commit has no ACKs. Tree-SHA512: 3c1272d9a3fd2874c5b2fc3c757bf6c5d195465baa413f898c8864c808224ee76ce83687fcab26802d7b2bb06235b7831d28befe222d3d392dc327910f47f084
It seems this also works:
mergin the two locations, but it does not work for HTTPs using a named location. |
I'm going to keep it as it's for the time being. It would be nice to try to simplify the configuration. |
To follow breaking changes in the Index config TOML files and env var names.
To follow breaking changes in the Index config TOML files and env var names.
To follow breaking changes in the Index config TOML files and env var names.
To follow breaking changes in the Index config TOML files and env var names.
fe02253 fix: [#6] update index configuration (Jose Celano) Pull request description: To follow breaking changes in the Index config TOML files and env var names. ACKs for top commit: josecelano: ACK fe02253 Tree-SHA512: 7254dc1ff0627dd7e0b730128555fcdbbdecbdc2e1a6d4c5c90a994868edfdac0ff97d53b28fbef41fd145489b753c0d7b6bf8016c6950d9e35afdc947b9771b
There were some breaking changes in the tracker configuration. See: torrust/torrust-tracker#878
857ca4c fix: [#6] update tracker configuration (Jose Celano) Pull request description: There were some breaking changes in the tracker configuration. See: torrust/torrust-tracker#878 ACKs for top commit: josecelano: ACK 857ca4c Tree-SHA512: 46dd732fdbfd6bf465593da75ed0fe9f4029ee00021363aea84df5737a358653a3dd2dca7d09468eb3d5589cd16c50e4be4da8700c7427ec0c899105b84115f8
In the droplet compose example the image proxy for torrent description is not working:
https://index.torrust-demo.com/api/v1/proxy/image/https%3A%2F%2Fraw.githubusercontent.com%2Ftorrust%2Ftorrust-index%2Fdevelop%2Fdocs%2Fmedia%2Ftorrust_logo.png
The text was updated successfully, but these errors were encountered: