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

Subdirectory Nginx Proxy_pass #334

Closed
jonathanmmm opened this issue Jun 14, 2021 · 5 comments
Closed

Subdirectory Nginx Proxy_pass #334

jonathanmmm opened this issue Jun 14, 2021 · 5 comments
Assignees
Labels

Comments

@jonathanmmm
Copy link

jonathanmmm commented Jun 14, 2021

Hi,

I found this one #101 but this is not about nginx.
and tried many different ways, but I can't get it right

server {
listen 8080;
server_name  10.8.0.1;
  location /mysql {
    rewrite /mysql/([^/]+) /$1 break;
    set $upstream_phpmyadmin phpmyadmin:80;
    proxy_pass http://upstream_phpmyadmin/;
    proxy_pass_header Content-Type;
  }
}

The PMA_URI is in docker-compose.yml
- PMA_ABSOLUTE_URI=http://10.8.0.1/mysql/

nginx is inside a container and has -p 80:8080 to the outside world

I get the following error in browser (chromium) console:
crbug/1173575, non-JS module files deprecated.

sometimes I got 404 forbidden or not found, e.g. with css/js, tried a lot and couldn't get it to work.

Does somebody know how to solve this?
I try the same setup with an phplapadmin container and it didn't work either.

without subfolder it works.

@williamdes
Copy link
Member

What version are you using?

@jonathanmmm
Copy link
Author

jonathanmmm commented Jun 14, 2021

I am using:
phpmyadmin 5.1.1 (from webinterface)

in docker-compose I use:

image: phpmyadmin

@williamdes
Copy link
Member

Thank you !

I think you meant "in the docker-compose network" for "nginx is inside a container and has -p 80:8080 to the outside world"

Config to reproduce the error

version: "3"

services:
  phpmyadmin-frontend:
    image: phpmyadmin:latest
    environment:
        PMA_ABSOLUTE_URI: http://localhost:8075/mysql/
  nginx:
    image: nginx:alpine
    volumes:
      - "./nginx.conf:/etc/nginx/conf.d/nginx.conf"
    ports:
      - "8075:8080"
server {
 listen 8080;
 server_name localhost;
   location /mysql {
     rewrite /mysql/([^/]+) /$1 break;
     set $upstream_phpmyadmin phpmyadmin-frontend:80;
     proxy_pass http://upstream_phpmyadmin/;
     proxy_pass_header Content-Type;
   }
}

Config to fix the error

I think http://upstream_phpmyadmin/; was meant to be http://$upstream_phpmyadmin/; and the rewrite regex was not working

Source: https://stackoverflow.com/a/47447211/5155484

.
├── docker-compose.yml
└── nginx.conf

0 directories, 2 files
version: "3"

services:
  phpmyadmin-frontend:
    image: phpmyadmin:latest
    container_name: phpmyadmin-frontend
    environment:
        PMA_ABSOLUTE_URI: http://localhost:8075/mysql/

  nginx:
    image: nginx:alpine
    volumes:
      - "./nginx.conf:/etc/nginx/conf.d/nginx.conf:ro"
    ports:
      - "8075:8080"
server {
 listen 8080;
 server_name localhost;
 set $upstream_phpmyadmin phpmyadmin-frontend:80;
   location /mysql {
     resolver 127.0.0.11; # Docker internal DNS
     rewrite ^/mysql(/.*)$ $1 break;
     proxy_pass http://$upstream_phpmyadmin;
     proxy_set_header X-Real-IP  $remote_addr;
     proxy_set_header X-Forwarded-For $remote_addr;
     proxy_set_header Host $host;
   }
}

Url to access: http://localhost:8075/mysql/ (last / is very important)

@williamdes williamdes self-assigned this Jun 14, 2021
@jonathanmmm
Copy link
Author

Oh, the last / could be the factor, I never tried it that way, thanks.

Great, it works.
I had to put the set $upstream_phpmyadmin outside the location, inside I got:

2021/06/14 18:12:47 [warn] 32#32: *23 using uninitialized "upstream_phpmyadmin" variable, client: 10.8.0.2, server: 10.8.0.1, request: "GET /mysql/ HTTP/1.1", host: "10.8.0.1"
2021/06/14 18:12:47 [error] 32#32: *23 invalid URL prefix in "http://", client: 10.8.0.2, server: 10.8.0.1, request: "GET /mysql/ HTTP/1.1", host: "10.8.0.1"

and yes, there was a $ missing, but tried before correctly.

Many thanks :-)

@williamdes
Copy link
Member

@ibennetch should we add this example to the documentation?

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

No branches or pull requests

2 participants