Skip to content
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

Regardless of the urlBase settings, reverse proxy access thru NGINX does not work with domain/subfolder #854

Open
Tos26 opened this issue Mar 14, 2024 · 6 comments

Comments

@Tos26
Copy link

Tos26 commented Mar 14, 2024

Hello,

I have Nginx as front end in my server (based on raspberry pi).
Several services work well with reverse proxy configured in Nginx with subfolder in URL :

https://mydomain.com/app1
https://mydomain.com/app2

So I would like to do the same thing with pigallery2 but it fails.

Here is my conf on nginx side:

  # Reverse Proxy PiGallery2 server
    location /photos {
            proxy_pass http://127.0.0.1:port;
            proxy_http_version 1.1;
            proxy_set_header X-Forwarded-Fpigallery2or $proxy_add_x_forwarded_for;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection 'upgrade';
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
   }

and I set config.json like that:

"urlBase": "/photos",

( I also try without / at the beginning, with / at the end, no effect)

The result in Firefox for https://mydomain.com/photos:
image

I already posted about this behavior : #388 but I couldn't go deeper after that.

Today, I restart this discussion in order to try to fix this issue.
I can't know if the failure comes from nginx or pigallery2 configuration (config.json)

Environment:

  • OS: Raspberry pi OS based on Debian 11 32 bits.
  • Firefox 123.0.1
  • Pigallery2 v2.0.0
  • Not docker
  • Node.JS v18.19.1
  • NGINX v1.18.0-6.1

Can I have some help on this topic?

Here is the debug console when I try to access to the server:
image
image

Let me know what kind of test I can perform to help the investigation.

Thank you in advance.

@Tos26 Tos26 changed the title Regardless of the urlBase settings, reverse proxy access via NGINX does not work with domain/subfolder Regardless of the urlBase settings, reverse proxy access thrue NGINX does not work with domain/subfolder Mar 15, 2024
@Tos26 Tos26 changed the title Regardless of the urlBase settings, reverse proxy access thrue NGINX does not work with domain/subfolder Regardless of the urlBase settings, reverse proxy access thru NGINX does not work with domain/subfolder Mar 15, 2024
@bpatrik
Copy link
Owner

bpatrik commented Mar 30, 2024

I don't have a proper nginx config at hand. If you want to set up manually, I would look at the sample nginx configuration in the docker folder of this repo.

If you use nginx proxy manager, setting this should work:

Screenshot_20240330_205228_Chrome.jpg

And on the Advanced tab:

gzip on;
	gzip_proxied any;
	gzip_comp_level 6;
	gzip_types
		text/css
		text/plain
		text/javascript
		text/markdown
		application/javascript
		application/json
		application/gpx+xml
		application/x-javascript
		application/xml
		application/xml+rss
		application/xhtml+xml
		application/x-font-ttf
		application/x-font-opentype
		application/vnd.ms-fontobject
		image/svg+xml
		image/x-icon
		application/rss+xml
		application/atom_xml;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

    # Only allow all methods (GET,POST,PUT,etc..) for root (/pgapi).
    # see https://github.com/bpatrik/pigallery2/issues/214
    location /pgapi { #<--- might need to change here 
      proxy_pass http://pigallery2:80; # forwarding to the other container, named 'pigallery2'
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }

    location / { # <--- might need to change here
      limit_except GET {
        deny  all;
      }
      proxy_pass http://pigallery2:80; # forwarding to the other container, named 'pigallery2'
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection 'upgrade';
      proxy_set_header Host $host;
      proxy_cache_bypass $http_upgrade;
    }

@Tos26
Copy link
Author

Tos26 commented Apr 2, 2024

Hello @bpatrik,

Thank you for your help.

I have continued my tests and I'm not sure that is a issue from nginx.

Explanation of tests:

I set that in the config.json:

{
    "Server": {
        "applicationTitle": "PiGallery 2",
        "//[publicUrl]": [
            "If you access the page form local network its good to know the public url for creating sharing link."
        ],
        "publicUrl": "",
        "//[urlBase]": [
            "If you access the gallery under a sub url (like: http://mydomain.com/myGallery), set it here. If it is not working you might miss the '/' from the beginning of the url."
        ],
        "urlBase": "/photos",
        "//[apiPath]": "PiGallery api path.",
        "apiPath": "/pgapi",

When I try to access to pigallery2 through my local network (then without nginx) at the address : 192.168.1.14:3900/photos, I get:

image

And if I try to access at the address without /photos in the URL, I get that ("loading" continuously):

image

I don't know the right config for apiPath but I tested to put /photos/pgapi with the same result.

So it seems to me that is a bad redirection due to a misunderstanding of the urlBase parameter...

What is your opinion about that ?

@bpatrik
Copy link
Owner

bpatrik commented Apr 4, 2024

To make it work you need two thing:

  1. have a reverse proxy that send traffic to the roor (i.e.: '/') of pigallery2, so it can load the index.html
  2. set the urlbase to the same thing that you set your reverse proxy too, so the calls from index.html contain the right url.

you do not really need to change the apipath (at all)

@Tos26
Copy link
Author

Tos26 commented Apr 8, 2024

Hi @bpatrik

Thank you for your help.
I still don't understand what is wrong.

I'm going to detail exactly my config:

  1. Install folder of pigallery2: /var/www/pigallery2
    image

  2. Content of nginx dedicated to pigallery2:

location /pigallery2 {
                 limit_except GET {
                    deny  all;
                 }
                 proxy_pass http://127.0.0.1:3900;
                 proxy_http_version 1.1;
                 proxy_set_header Upgrade $http_upgrade;
                 proxy_set_header Connection 'upgrade';
                 proxy_set_header Host $host;
                 proxy_cache_bypass $http_upgrade;
}

  1. urlBase in config.json:
{
    "Server": {
        "applicationTitle": "PiGallery 2",
        "//[publicUrl]": [
            "If you access the page form local network its good to know the public url for creating sharing link."
        ],
        "publicUrl": "",
        "//[urlBase]": [
            "If you access the gallery under a sub url (like: http://mydomain.com/myGallery), set it here. If it is not working you might miss the '/' from the beginning of the url."
        ],
        "urlBase": "/pigallery2",
        "//[apiPath]": "PiGallery api path.",
        "apiPath": "/pgapi",
  1. Tests:

So, maybe I didn't understand something in your explanation but to me:

  • location /pigallery2 should set the subfolder of the url for nginx
  • proxy_pass setting is localhost at port 3900, witch is the port I set in the config.json
  • Exactly the same kind of config in nginx works through subfolder with my other services (navidrome, calibre-web...)

From your point of vue, is it relevant to test with the docker version of pigallery2 or it will be the same behavior?
Can you confirm that my installation and configuration are correct?
What about the host configuration in the config.json?

        "port": 3900,
        "//[host]": [
            "Server will accept connections from this IPv6 or IPv4 address."
        ],
        "host": "0.0.0.0",

Thank you.

@Tos26
Copy link
Author

Tos26 commented May 23, 2024

Somebody can help me please ?

@bpatrik
Copy link
Owner

bpatrik commented May 23, 2024

Hi,
just checked. This worked for me:

  location /urltest/ {

and:
kép
You can also set in the env variables:
kép

Then I was opening http://mydoman.com/urltest


This is how the nginx setting works on nginx proxy manager:
kép

Which generated this file:

<...>
  location /urltest/ {
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-Scheme $scheme;
    proxy_set_header X-Forwarded-Proto  $scheme;
    proxy_set_header X-Forwarded-For    $remote_addr;
    proxy_set_header X-Real-IP		$remote_addr;
    proxy_pass       http://pigallery2:80/;
    
<...>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants