0
Answered

How to redirect :2022 to /library Nginx

Dallen Bishop 8 years ago updated by Daniel 1 year ago 17

I have tried everything that I find yet it doesn't want to work whether Nginx doesn't want to let style-sheets to pass through or it gives me a 502 bad gateway error that I can't fix. Here is my current Nginx config for Ubooquity. I can access Ubooquity through :2022 and it is configured for HTTPS.


location /library {

proxy_pass https://127.0.0.1:2222;

proxy_set_header Host $host;

}




Under review

Did you take a look at this thread ?

Yes, but sadly it still didn't work. With this config that I have listed below, it gives me a 502 Bad Gateway error, and I can't fix it.

location /library {

proxy_pass https://127.0.0.1:2022;

proxy_set_header Host $host;

}

When I start up Ubooquity, my --host option is set to 5.196.70.4 . When I use the config below, I can get some of the page to come through to /library but it is just links, the JS and CSS is not getting through. Chrome's Console gave me this:


Failed to load resource: the server responded with a status of 404 (Not Found)

https://mei-mei.pw/scripts/tools.js Failed to load resource: the server responded with a status of 404 (Not Found)

https://mei-mei.pw/theme/homepage.css Failed to load resource: the server responded with a status of 404 (Not Found)


The other nginx config is:


location /library {

proxy_pass https://5.196.70.4:2022;

proxy_set_header Host $host;

}

When I try http: it doesn't work at all.


https://mei-mei.pw/library

https://mei-mei.pw:2022

I'll try to test it on my side in a few days, but as far as I know, the reverse proxy feature is working fine.

I'll let you know the result of my test once it's done.

By the way, make sure you use version 1.8.2 of Ubooquity. Version 1.8.0 had a bug which might cause the problem you are describing.

I am having similar issues trying to get https working with nginx. I am able to get https://localhost:2202/ubooquity to work just fine, but I am unable to get https://mydomain.net/ubooquity to work. It does load a black and white text only page with "Please identify yourself" in the upper left hand corner along with user ID and password boxes and a login button. I am unable to login. https://mydomain.net/ubooquity/admin provides the exact results where as https://localhost:2202/ubooquity/admin works as expected.


Here is the config in my nginx conf file:


location /ubooquity/ {

proxy_pass https://localhost:2202/ubooquity;

proxy_set_header Host $host;
}

I also have the Reverse proxy prefix set to ubooquity on the advanced tab of the ubooquity server admin page. I have reloaded the nginx config after my last update to the conf file and restarted the ubooquity server as well. I have https and nginx working successfully for 3 other applications. I checked the ubooquity logs and there are no errors or warnings present.


I am running jre1.8.0_91, nginx 1.10.0, and ubooquity 1.9.1.


Any help is appreciated.

a black and white text only page with "Please identify yourself" in the upper left hand corner along with user ID and password boxes and a login button

Seems like the browser cannot find the CSS and images used by the login page. Did you try to clear the cache of your browser ?

If you get a proper login page after the cache clearing, please let me know so that I can focus on the remaining parts of the problem.


As for the main issue, it would be interesting to determine if your problem comes from the HTTPS or the reverse proxy feature.

Did you (or could you) try the following setups:


  • No HTTPS, with reverse proxy through nginx (i.e. accessing Ubooquity via http://mydomain.net/ubooquity/ )
  • HTTPS without reverse proxy, still through nginx (i.e. accessing Ubooquity via https://mydomain.net/)

Knowing which one works and which one doesn't would help delimiting the problem.

Cleared cache with same results. I have also tried with Chrome, Firefox, and Edge browses with same result.


Without nginx using http and no reverse proxy prefix

With nginx using http and reverse proxy prefix set to ubooquity

Without nginx using https and no reverse proxy prefix

With nginx using https and reverse proxy prefix set to ubooquity

  • https://localhost/ubooquity - Does not work. I get a black and white text only page with "Please identify yourself" in the upper left hand corner along with user ID and password boxes and a login button.
  • https://mydomain.net/ubooquity - Does not work. I get a black and white text only page with "Please identify yourself" in the upper left hand corner along with user ID and password boxes and a login button.
  • Let me know if there is anything else I can test to help narrow it down.

    What configuration lines do you have in the server section (of nginx) above "location" ? (especially the values for "listen" and "server_name")


    I'm playing with nginx and haven't managed to reproduced the problem on my side yet.

    But I have never really used it for more than a few tests, so I'm really far from being an nginx expert.




    Here is the start of the server section and below it is another location that is working without issue. I also do have port forwarding turned on at my external router for ports 80, 443, and 2202 for this testing.


    server {

    listen 80;

    listen 443 ssl;

    server_name mydomain.net 192.168.1.103;

    ssl_certificate /users/mark/documents/nginx-1.10.0/conf/nginx.crt;

    ssl_certificate_key /users/mark/documents/nginx-1.10.0/conf/nginx.key;


    location /cp {

    proxy_pass https://192.168.1.103:5050/cp/;

    proxy_set_header X-Real-IP $remote_addr;

    proxy_redirect default;

    proxy_set_header Host localhost:5000;

    }


    To be honest, I think this problem requires real nginx skills that I don't have. :(


    Just a remark: if you already use nginx to encapsulate your connection in HTTPS, you don"t need to activate it in Ubooquity.


    Another angle to attack the problem would be to try to understand why you can access the HTML code of the login page (when you get the text only page) but not the images and CSS that are linked by this login page.

    You could try to open the login page and find an image link in its HTML, then try to access it directly from your browser by pasting its URL in the address bar.


    Perhaps the link or the behavior of nginx could provide a clue...


    Seems like a lot of people have problems with css working properly with nginx. I enabled access logging for nginx to show what files are being requested when the login page loads. Below is all that gets logged when the web page loads. My themes directory is empty and I do not have a scripts folder. I tried adding root to my nginx conf to tell it where to look as well as some other commands for mime.types and other things I saw people suggesting with no luck.


    10.10.10.10 - - [08/May/2016:09:00:49 -0500] "POST /ubooquity/ HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"


    10.10.10.10 - - [08/May/2016:09:00:49 -0500] "GET /ubooquity/theme/homepage.css HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"
    10.10.10.10 - - [08/May/2016:09:00:49 -0500] "GET /ubooquity/scripts/tools.js HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"
    10.10.10.10 - - [08/May/2016:09:00:50 -0500] "GET /ubooquity/scripts/sha256-min.js HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"
    10.10.10.10 - - [08/May/2016:09:00:50 -0500] "GET /ubooquity/theme/android-chrome-192x192.png HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"
    10.10.10.10 - - [08/May/2016:09:00:50 -0500] "GET /ubooquity/theme/favicon-96x96.png HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"
    10.10.10.10 - - [08/May/2016:09:00:50 -0500] "GET /ubooquity/theme/favicon-32x32.png HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"
    10.10.10.10 - - [08/May/2016:09:00:50 -0500] "GET /ubooquity/theme/favicon-16x16.png HTTP/1.1" 200 2402 "https://mydomain.net/ubooquity/"

    Try these configurations (verbatim, slashes are important):


    location /ubooquity/ {
        proxy_pass https://localhost:2202;
        proxy_set_header Host $host;
    }
    

    location /ubooquity/ {
        proxy_pass https://localhost:2202/ubooquity/;
        proxy_set_header Host $host;
    }
    

    My guess is that both of them will work.

    Adding the trailing slash after ubooquity on the proxy_pass in the sections below fixed it. Thanks!


    location /ubooquity/ {

    proxy_set_header Host $host;
    }
    Answered

    Great !


    Now if you understand why it works (like I said, I don't know much about nginx), let me know.

    this is because without the trailing slash, its just appending the file names to the end like it would if it was my.domain.com:2202/ so instead of :2202/library/image.png, its trying to do 2202/libraryimage.png. nginx loves the trailing slashes lol. my issue is in ubooquity, if i put the reverse proxy prefix as /ubooquity, or ubooquity/, or /ubooquity/ i get an error. i will add the error when my laptop isnt at 5% life lol.

    The documentation is probably not explicit enough, but the reverse proxy prefix in the advanced settings is not supposed to contain slashes. Just "ubooquity" should be enough.

    +1

    Necro-ing this thread as I have a working answer that may help people (like me) when I was searching for an answer.

    I am adding Ubooquity as a subdomain (books) of my domain (website.com). The intended outcome was to go to books.website.com and reach my ubooquity server on a docker container managed by Nginx proxy manager.

    • Add a Proxy Host with the desired full url (ie: book.website.com) on the Details tab.
    • Scheme is http even if you implement https on your site (remember this is looking at internal routing!).
    • Forward Hostname/IP is your internal IP of your docker host server (ie: my docker is on a computer with a local IP of 192.168.2.21. That's the IP you want).
    • The Forward Port is the port looking into the docker container (ie: Ubooquity docker non-admin port is 2202. This is the port I want).
    • I always check Websockets Support and Block Common Exploits. You can probably check cache assets as well.

    Then go to the Custom Location tab. Here we will add the details of how Nginx make the correct connection to Ubooquity.

    • Under Define Location, put the the url ending that would come after the port in the local address (ie: To access Ubooquity on my local network I would type this into my address bar '192.168.2.21:2022/ubooquity'. We want what comes after the port number not including the slashes 'ubooquity'.
    • Scheme is again http, we are still identifying items in our local network.
    • Forward Hostname/IP is again the IP of your docker host server '192.168.2.21'.
    • Forward Port is 80.

    Finally, on the SSL tab, if you are using SSL, add your server certificate here. I usually check Force SSL and HTTP/2 Support.

    There is one little glitch that I can't quite figure out yet is when you browse to the main domain (books.website.com) it forwards like twenty /ubooquity/ levels then the port number /:2202/. Still works and goes away when you navigate into the main library.

    Hope this helps!