[GH-ISSUE #39] Unable to host under subpath #27

Closed
opened 2026-02-25 23:33:17 +03:00 by kerem · 18 comments
Owner

Originally created by @Necklaces on GitHub (Mar 3, 2018).
Original GitHub issue: https://github.com/go-shiori/shiori/issues/39

I'm trying to host shiori on port 7777 and then proxy pass https://localhost/shiori/ to that port, but when I do using this nginx config:

  location /shiori/ {
    rewrite ^/shiori/(.*)$ /$1 break;
    proxy_pass http://localhost:7777;
    proxy_redirect http://localhost:7777/ $scheme://$host/shiori/;
  }

I get this result:

This page isn’t working

And the URL shows:

https://localhost/login

Any ideas? Seems like shiori redirects to / (root).

Manually going to localhost/shiori/login brings up a broken login page, seemingly without both css, images, etc (can't click on anything).

Originally created by @Necklaces on GitHub (Mar 3, 2018). Original GitHub issue: https://github.com/go-shiori/shiori/issues/39 I'm trying to host shiori on port 7777 and then proxy pass https://localhost/shiori/ to that port, but when I do using this nginx config: ``` location /shiori/ { rewrite ^/shiori/(.*)$ /$1 break; proxy_pass http://localhost:7777; proxy_redirect http://localhost:7777/ $scheme://$host/shiori/; } ``` I get this result: > This page isn’t working And the URL shows: > https://localhost/login Any ideas? Seems like shiori redirects to `/` (root). Manually going to `localhost/shiori/login` brings up a broken login page, seemingly without both css, images, etc (can't click on anything).
Author
Owner

@RadhiFadlillah commented on GitHub (Mar 10, 2018):

Hi @Necklaces sorry for late response.

I'm sorry, unfortunately I don't have any experience using nginx, so I can't give any advice. Usually I just use caddy since it served HTTPs by default.

If others has any advice or solution feels free to comment.

<!-- gh-comment-id:372031471 --> @RadhiFadlillah commented on GitHub (Mar 10, 2018): Hi @Necklaces sorry for late response. I'm sorry, unfortunately I don't have any experience using `nginx`, so I can't give any advice. Usually I just use `caddy` since it served HTTPs by default. If others has any advice or solution feels free to comment.
Author
Owner

@peteretelej commented on GitHub (Mar 11, 2018):

proxy_redirect only rewrites headers (eg Location), shiori redirects to /login, hence your should be proxy_redirect / $scheme://$host/shiori/; for the login page to redirect properly.

However this will not work with assets requested directly eg /css/,/js/ etc unless a rewrite is used .eg.
for location ~ ^/(css|js|api) to /shiori/, which I don't think would work well.

The issue also applies to caddy if the proxy isn't root, and a rewrite to for all request isn't used. e.g.

proxy /shiori http://localhost:8080 {  
        without /shiori                 
}                                       

Possible fix: adding a webroot flag for server cmd so that it can be used for paths, serve -webroot shiori this would need changing of asset sources in html files + redirects to include the webroot variable.

<!-- gh-comment-id:372105187 --> @peteretelej commented on GitHub (Mar 11, 2018): `proxy_redirect` only rewrites headers (eg Location), shiori redirects to /login, hence your should be `proxy_redirect / $scheme://$host/shiori/;` for the login page to redirect properly. However this will not work with assets requested directly eg /css/,/js/ etc unless a rewrite is used .eg. for `location ~ ^/(css|js|api)` to /shiori/, which I don't think would work well. The issue also applies to caddy if the proxy isn't root, and a `rewrite to` for all request isn't used. e.g. ``` proxy /shiori http://localhost:8080 { without /shiori } ``` Possible fix: adding a **webroot** flag for server cmd so that it can be used for paths, `serve -webroot shiori` this would need changing of asset sources in html files + redirects to include the webroot variable.
Author
Owner

@ekianjo commented on GitHub (Sep 23, 2019):

@RadhiFadlillah can you provide a fix for this issue as suggested by @peteretelej ? Right now it's not possible to host it on a subdirectory with nginx...

<!-- gh-comment-id:533960160 --> @ekianjo commented on GitHub (Sep 23, 2019): @RadhiFadlillah can you provide a fix for this issue as suggested by @peteretelej ? Right now it's not possible to host it on a subdirectory with nginx...
Author
Owner

@RadhiFadlillah commented on GitHub (Oct 7, 2019):

Guys, I've implemented this in 99d2793. To use it, config your proxy (in this example I use Caddy) like this :

your-awesome-domain.com {
    proxy /shiori localhost:9000
}

Then run shiori serve with webroot flag set like this :

shiori serve -p 9000 --webroot /shiori

By the way, the webroot flag will change the entire API route to be prefixed with the specified root. For example, by running command above now the index is located in localhost:9000/shiori instead of localhost:9000.

<!-- gh-comment-id:538901406 --> @RadhiFadlillah commented on GitHub (Oct 7, 2019): Guys, I've implemented this in [99d2793](https://github.com/go-shiori/shiori/commit/99d27930eaee84746fa3fc777201b4baa7738672). To use it, config your proxy (in this example I use Caddy) like this : ``` your-awesome-domain.com { proxy /shiori localhost:9000 } ``` Then run `shiori serve` with `webroot` flag set like this : ``` shiori serve -p 9000 --webroot /shiori ``` --- By the way, the `webroot` flag will change the entire API route to be prefixed with the specified root. For example, by running command above now the index is located in `localhost:9000/shiori` instead of `localhost:9000`.
Author
Owner

@ekianjo commented on GitHub (Oct 7, 2019):

Wow very nice this deserves a new release!

On Monday, October 7, 2019, Radhi notifications@github.com wrote:

Guys, I've implemented this in 99d2793. For example, says you have
Caddyfile configured like this :

your-awesome-domain.com {
proxy /shiori localhost:9000
}

Now you only need to run shiori serve with webroot flag set like this :

shiori serve -p 9000 --webroot /shiori


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.<
https://ci6.googleusercontent.com/proxy/CLJs0DCbNvW0HGRFsVH98uMrm60ekrcajpNR-mlsKVfFrj9txzx0xhJPd34U4oLarQbQKdbfAOER7Oolh9Vb6_HkCrXSXvC6Mwr3Skk8wZ7TTB4wTsUvbY90Eiu5sLhnX5F2ijbkcfseqzWpQlnpeDJqJ6E56FlpIwD2kDS3wxKu1V_jRp7MjxpVM4JhEK5o-ega4oYthIwVhECbb00HekQChCW0SKS9n_1tFqDImw=s0-d-e1-ft#https://github.com/notifications/beacon/AASYZGHIPVODYYFJKRABNELQNLZ37A5CNFSM4ETMHC42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPPXHQ.gif

--
Raphael

<!-- gh-comment-id:538911640 --> @ekianjo commented on GitHub (Oct 7, 2019): Wow very nice this deserves a new release! On Monday, October 7, 2019, Radhi <notifications@github.com> wrote: > Guys, I've implemented this in 99d2793. For example, says you have Caddyfile configured like this : > > your-awesome-domain.com { > proxy /shiori localhost:9000 > } > > Now you only need to run shiori serve with webroot flag set like this : > > shiori serve -p 9000 --webroot /shiori > > — > You are receiving this because you commented. > Reply to this email directly, view it on GitHub, or mute the thread.< https://ci6.googleusercontent.com/proxy/CLJs0DCbNvW0HGRFsVH98uMrm60ekrcajpNR-mlsKVfFrj9txzx0xhJPd34U4oLarQbQKdbfAOER7Oolh9Vb6_HkCrXSXvC6Mwr3Skk8wZ7TTB4wTsUvbY90Eiu5sLhnX5F2ijbkcfseqzWpQlnpeDJqJ6E56FlpIwD2kDS3wxKu1V_jRp7MjxpVM4JhEK5o-ega4oYthIwVhECbb00HekQChCW0SKS9n_1tFqDImw=s0-d-e1-ft#https://github.com/notifications/beacon/AASYZGHIPVODYYFJKRABNELQNLZ37A5CNFSM4ETMHC42YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAPPXHQ.gif > -- Raphael
Author
Owner

@kimpers commented on GitHub (Oct 12, 2019):

I'm still having issues with this when using the docker image. After I login with --webroot set the browser gets stuck in an infinite redirect loop.

Reproduction case:

  1. Run: docker run -p 9000:9000 radhifadlillah/shiori:latest shiori serve -p 9000 --webroot /shiori
  2. Try to login on http://localhost:9000/shiori with default credentials and you will get a too many redirects error screen after a successful login.

If I remove the --webroot /shiori parameter then everything works as expected.

<!-- gh-comment-id:541345032 --> @kimpers commented on GitHub (Oct 12, 2019): I'm still having issues with this when using the docker image. After I login with `--webroot` set the browser gets stuck in an infinite redirect loop. Reproduction case: 1. Run: `docker run -p 9000:9000 radhifadlillah/shiori:latest shiori serve -p 9000 --webroot /shiori` 1. Try to login on http://localhost:9000/shiori with default credentials and you will get a too many redirects error screen after a successful login. If I remove the `--webroot /shiori` parameter then everything works as expected.
Author
Owner

@wangxu94 commented on GitHub (Dec 17, 2019):

I'm having the same issue as @kimpers above.

Reproduction:

  1. Build shiori from source following the documentation here
  2. Run: shiori serve -p 8082 --webroot /shiori --portable
  3. Try to login on http://<server_url>:8082/shiori and got this error:
    firefox_QEbqdkSC7L
  4. Set up an Apache reverse proxy with settings:
    <Location /shiori>
        Require valid-user
        AuthType basic
        AuthFormProvider file
        AuthFormLoginSuccessLocation /shiori
        AuthUserFile "/etc/apache2/passwd"
        AuthName "My Login"
        Session On
        SessionMaxAge 1800
        SessionCookieName session path=/
        SessionCryptoPassphrase <passphrase>
        ErrorDocument 401 /login.html
        ProxyPass http://localhost:8082/shiori
        ProxyPassReverse http://localhost:8082/shiori
        RequestHeader set X-Forwarded-Proto "https"
        RequestHeader set X-Forwarded-Port "443"
    </Location>
  1. Get the same redirection error.

Everything works fine without the webroot option.

<!-- gh-comment-id:566788820 --> @wangxu94 commented on GitHub (Dec 17, 2019): I'm having the same issue as @kimpers above. Reproduction: 1. Build shiori from source following the documentation [here](https://github.com/go-shiori/shiori/wiki/Installation) 2. Run: `shiori serve -p 8082 --webroot /shiori --portable` 3. Try to login on http://<server_url>:8082/shiori and got this error: ![firefox_QEbqdkSC7L](https://user-images.githubusercontent.com/15028233/71041361-bfc9cc00-218d-11ea-9618-21c4510bb31c.png) 4. Set up an Apache reverse proxy with settings: ``` <Location /shiori> Require valid-user AuthType basic AuthFormProvider file AuthFormLoginSuccessLocation /shiori AuthUserFile "/etc/apache2/passwd" AuthName "My Login" Session On SessionMaxAge 1800 SessionCookieName session path=/ SessionCryptoPassphrase <passphrase> ErrorDocument 401 /login.html ProxyPass http://localhost:8082/shiori ProxyPassReverse http://localhost:8082/shiori RequestHeader set X-Forwarded-Proto "https" RequestHeader set X-Forwarded-Port "443" </Location> ``` 5. Get the same redirection error. Everything works fine without the webroot option.
Author
Owner

@NBonaparte commented on GitHub (Apr 19, 2020):

If anyone's still interested, I think I found the source of the issue. path.Join trims the trailing slash if the path isn't / (see aa339d7706ef42b977f574bb77dee1c2ee3a1734)

<!-- gh-comment-id:616232447 --> @NBonaparte commented on GitHub (Apr 19, 2020): If anyone's still interested, I think I found the source of the issue. `path.Join` trims the trailing slash if the path isn't `/` (see aa339d7706ef42b977f574bb77dee1c2ee3a1734)
Author
Owner

@davidnewhall commented on GitHub (Nov 5, 2020):

Now if only we can get that fix into the codebase. :) cc @deanishe

<!-- gh-comment-id:722299994 --> @davidnewhall commented on GitHub (Nov 5, 2020): Now if only we can get that fix into the codebase. :) cc @deanishe
Author
Owner

@Systemsemaphore commented on GitHub (Nov 12, 2020):

+1, I need this. Currently using binary shiori-linux-amd64-stretch

error_unknown_flag

<!-- gh-comment-id:726207930 --> @Systemsemaphore commented on GitHub (Nov 12, 2020): +1, I need this. Currently using binary `shiori-linux-amd64-stretch` ![error_unknown_flag](https://user-images.githubusercontent.com/74195074/98971184-2035ca80-2511-11eb-80a6-3460322c91ac.png)
Author
Owner

@rbdevr commented on GitHub (Nov 22, 2020):

hello all,

I'm trying to run shiori behind apache.

shiori - http://localhost:5000/shiori

shiori serve -p 5000 --webroot /shiori

apache - http://myserver/shiori

<Location "/shiori">
Require all granted
ProxyPass http://localhost:5000/shiori
ProxyPassReverse http://localhost:5000/shiori
</Location>

I'm getting the following error:

"
The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

This problem can sometimes be caused by disabling or refusing to accept cookies.
"

Are you guys working on this issue?

Cheers

<!-- gh-comment-id:731863884 --> @rbdevr commented on GitHub (Nov 22, 2020): hello all, I'm trying to run shiori behind apache. shiori - http://localhost:5000/shiori shiori serve -p 5000 --webroot /shiori apache - http://myserver/shiori `<Location "/shiori">` ` Require all granted` ` ProxyPass http://localhost:5000/shiori` ` ProxyPassReverse http://localhost:5000/shiori` `</Location>` I'm getting the following error: " The page isn't redirecting properly Firefox has detected that the server is redirecting the request for this address in a way that will never complete. This problem can sometimes be caused by disabling or refusing to accept cookies. " Are you guys working on this issue? Cheers
Author
Owner

@KarolBedkowski commented on GitHub (Jan 17, 2021):

Hi,
Cookie with session id has wrong path when shiori is served under subpath.
Above patch solve problem.

<!-- gh-comment-id:761762708 --> @KarolBedkowski commented on GitHub (Jan 17, 2021): Hi, Cookie with session id has wrong path when shiori is served under subpath. Above patch solve problem.
Author
Owner

@stale[bot] commented on GitHub (Feb 10, 2022):

This issue has been automatically marked as stale because it has not had any activity for quite some time.
It will be closed if no further activity occurs.
Thank you for your contributions.

<!-- gh-comment-id:1035560844 --> @stale[bot] commented on GitHub (Feb 10, 2022): This issue has been automatically marked as stale because it has not had any activity for quite some time. It will be closed if no further activity occurs. Thank you for your contributions.
Author
Owner

@efrecon commented on GitHub (Feb 16, 2022):

I have a fork that contains the fix from @NBonaparte above, and also generates an access log. I fixed the github workflows so they generate packages named after the organisation and repository hosting the project (i.e. not hardcoded to go-shiori/shiori). In other words: Docker images are available within my fork if you wanted so.

These are "good to have" changes. @fmartingr would you accept a PR?

<!-- gh-comment-id:1042326273 --> @efrecon commented on GitHub (Feb 16, 2022): I have a [fork](https://github.com/efrecon/shiori) that contains the fix from @NBonaparte above, and also generates an access log. I fixed the github workflows so they generate packages named after the organisation and repository hosting the project (i.e. not hardcoded to `go-shiori/shiori`). In other words: Docker images are available within my fork if you wanted so. These are "good to have" changes. @fmartingr would you accept a PR?
Author
Owner

@efrecon commented on GitHub (Feb 16, 2022):

On a side note: I noticed that this is marked with a note:fixed?, but this isn't fixed entirely until what @NBonaparte proposed and/or the content of my fork is taken in.

<!-- gh-comment-id:1042330129 --> @efrecon commented on GitHub (Feb 16, 2022): On a side note: I noticed that this is marked with a `note:fixed?`, but this isn't fixed entirely until what @NBonaparte proposed and/or the content of my fork is taken in.
Author
Owner

@fmartingr commented on GitHub (Feb 17, 2022):

These are "good to have" changes. @fmartingr would you accept a PR?

Of course! This has to be one of the issues with the most activity, so if this is a requirement for you folks I will gladly accept a PR with the fix. The access log seems useful too, but it has to be optional (default to false) so people can avoid filling storage with it if they don't want to.

<!-- gh-comment-id:1043429459 --> @fmartingr commented on GitHub (Feb 17, 2022): > These are "good to have" changes. @fmartingr would you accept a PR? Of course! This has to be one of the issues with the most activity, so if this is a requirement for you folks I will gladly accept a PR with the fix. The access log seems useful too, but it has to be optional (default to false) so people can avoid filling storage with it if they don't want to.
Author
Owner

@davidnewhall commented on GitHub (Feb 17, 2022):

Fundamentally, access logs on web servers should never be disabled by default. Recommend log rotation by default.

<!-- gh-comment-id:1043628450 --> @davidnewhall commented on GitHub (Feb 17, 2022): Fundamentally, access logs on web servers should never be disabled by default. Recommend log rotation by default.
Author
Owner

@efrecon commented on GitHub (Feb 18, 2022):

PR #374 sent. As suggested by @davidnewhall, logging in on by default, but can be turned off with --log=false at the command-line if necessary.

<!-- gh-comment-id:1044692052 --> @efrecon commented on GitHub (Feb 18, 2022): PR #374 sent. As suggested by @davidnewhall, logging in on by default, but can be turned off with `--log=false` at the command-line if necessary.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/shiori#27
No description provided.