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

How to use in subdirectory #101

Closed
kujiy opened this issue Dec 15, 2016 · 13 comments
Closed

How to use in subdirectory #101

kujiy opened this issue Dec 15, 2016 · 13 comments
Assignees
Labels

Comments

@kujiy
Copy link
Contributor

@kujiy kujiy commented Dec 15, 2016

Is is possible that I launch it as http://example.com/phpmyadmin/ ?

PMA_ABSOLUTE_URI seemed not work.

@nijel

This comment has been minimized.

Copy link
Member

@nijel nijel commented Dec 15, 2016

Do you use latest version, PMA_ABSOLUTE_URI sould be the way to do it, but it's not supported on anything older than 4.6.5.

@nijel nijel self-assigned this Dec 15, 2016
@nijel nijel added the question label Dec 15, 2016
@kujiy

This comment has been minimized.

Copy link
Contributor Author

@kujiy kujiy commented Dec 15, 2016

Thanks @nijel I'll check the version tomorrow. I thought I excuted docker pull phpmyadmin/phpmyadmin:latest today. I was wondering that my container ran with php command not nginx and supervisor. I might take some mistakes...

@nijel

This comment has been minimized.

Copy link
Member

@nijel nijel commented Dec 15, 2016

That sounds correcty, but if there is no supervisor, it's clearly some older version. Maybe I've made something wrong in the docker hub tags setup....

@kujiy

This comment has been minimized.

Copy link
Contributor Author

@kujiy kujiy commented Dec 15, 2016

@nijel I feel that's understandable for me. I'd had old container at the moment so I did docker pull and docker rm -f container then docker-compose up. But there's no supervisor inside the container. I'd like to know your recommended tag, thanks.

@kujiy

This comment has been minimized.

Copy link
Contributor Author

@kujiy kujiy commented Dec 16, 2016

Hi @nijel, I was wrong that I specified an old image in docker-compose.yml. I'm sorry to bother you. Now I launched the latest container Version 4.6.5.2. But PMA_ABSOLUTE_URI seemed not to work for subdirectory. I'm wondering where your subdirectory code is. My /etc/nginx.conf is completely same as its original, there's no alias. (I tried to add those lines but couldn't make it work... I've got to learn nginx first).

Could you tell me how you tried a web server to have an alias?

@nijel

This comment has been minimized.

Copy link
Member

@nijel nijel commented Dec 16, 2016

The PMA_ABSOLUTE_URI doesn't change the path where phpMyAdmin is served from the container (it's always on /), it's there for possibility to run it behind reverse proxy which will change the location.

It's there for handing following setups:

(reverse proxy)         <->  (phpMyAdmin docker)
https://host/some/path/      http://1.2.3.4/

Here phpMyAdmin would think it's running on http://1.2.3.4/, while the user sees it at https://host/some/path/. In such case setting PMA_ABSOLUTE_URI=https://host/some/path/ is needed.

@kujiy

This comment has been minimized.

Copy link
Contributor Author

@kujiy kujiy commented Dec 16, 2016

I used phpmyadmin behind haproxy so tried to setup haproxy as a ProxyPass and works!

Here's my haproxy settings for subdirectoried phpmyadmin .

frontend http
    bind *:80
    option forwardfor
    option http-server-close

    ### NETWORK restriction
    acl LOCALNET  src 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12

    # /phpmyadmin
    acl phpmyadmin  path_dir /phpmyadmin
    use_backend phpmyadmin if phpmyadmin LOCALNET  

backend phpmyadmin
    mode http

    # ProxyPass /phpmyadmin/ http://172.30.21.21/
    reqirep  ^(GET|POST|HEAD)\ /phpmyadmin/(.*)     \1\ /\2 

    server localhost     172.30.21.21:80                # <- phpmyadmin container IP

Here's docker-compose.yml for phpmyadmin.

version: '2'

services:
  phpmyadmin:
    restart: always
    image: phpmyadmin/phpmyadmin
    container_name: phpmyadmin
    hostname: phpmyadmin
    domainname: example.com
    ports:
      - 8000:80
    environment:
      - PMA_HOSTS=172.26.36.7,172.26.36.8,172.26.36.9,172.26.36.10
      - PMA_VERBOSES=production-db1,production-db2,dev-db1,dev-db2
      - PMA_USER=root
      - PMA_PASSWORD=
      - PMA_ABSOLUTE_URI=http://example.com/phpmyadmin/
    networks:
      example.com:
        ipv4_address: 172.30.21.21                # <- Specified container IP for haproxy

networks:
  example.com:
    external: true

Now they're working perfectly. Thank you very much. Would my settings be added to your document perhaps?

@nijel

This comment has been minimized.

Copy link
Member

@nijel nijel commented Dec 16, 2016

Adding that to the docs could be useful, can you please document your setup for our docs? It's here: https://github.com/phpmyadmin/phpmyadmin/blob/master/doc/setup.rst#installing-using-docker

@lkaybob

This comment has been minimized.

Copy link

@lkaybob lkaybob commented Apr 28, 2017

Hello, I'm using phpMyAdmin 4.7.0 on Docker along with traefik reverse proxy. I'm experiencing a similar issue on setting up subdirectory.

I used following docker-compose.yml file, with PMA_ABSOLUTE_URL

version: '2'

services:
   myadmin:
     container_name: PHPMyAdmin
     external_links:
       - db
     image: phpmyadmin/phpmyadmin
     networks:
       - web
       - back-end
     restart: always
     environment:
       - PMA_HOST=172.19.0.4
       - PMA_PORT=3306
       - PMA_ABSOLUTE_URI=http://192.168.99.100/phpmyadmin/

networks:
  web:
    external:
      name: ubuntu_webgateway
  back-end:
    external:
       name: 1doitpageconfig_back-end

Also, I set up reverse proxy to point phpMyadmin server with request URL's path to /phpmyadmin But the thing is phpMyAdmin launches at /. So I get 404 error when I access phpMyAdmin from browser with http://EXTERNAL_ADDRESS/phpmyadmin. I ran curl http://INTERNAL_PMA_ADDRESS/ and curl http://INTERNAL_PMA_ADDRESS/phpmyadmin on command line, and the latter one also returns 404 error

I tried to use PathPrefixStip option in reverse proxy. Then I can get index.php properly, but I get 400 error on static assets like CSS, JS, etc. So I think the only way is to make phpMyAdmin available at /phpMyAdmin. Is PMA_ABSOLUTE_URI option valid in 4.7.0 still?

UPDATE I will put request header when I'm trying to access phpMyAdmin at Chrome browser.
This is a request header for index.php with PathPrefixStrip enabled in reverse proxy.

GET /phpmyadmin HTTP/1.1
Host: 192.168.99.100
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2

HTTP/1.1 200 OK
Cache-Control: no-store, no-cache, must-revalidate,  pre-check=0, post-check=0, max-age=0
Content-Encoding: gzip
Content-Security-Policy: default-src 'self' ;script-src 'self' 'unsafe-inline' 'unsafe-eval' ;;style-src 'self' 'unsafe-inline' ;img-src 'self' data:  *.tile.openstreetmap.org;
Content-Type: text/html; charset=utf-8
Date: Fri, 28 Apr 2017 08:01:03 GMT
Expires: Fri, 28 Apr 2017 08:01:03 +0000
Last-Modified: Fri, 28 Apr 2017 08:01:03 +0000
Pragma: no-cache
Referrer-Policy: no-referrer
Server: nginx
...

and this is for phpmyadmin.css, which returns 400 Bad Request error

GET /phpmyadmin.css.php?nocache=4473505546ltr HTTP/1.1
Host: 192.168.99.100
Connection: keep-alive
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Accept: text/css,*/*;q=0.1
DNT: 1
Accept-Encoding: gzip, deflate, sdch
Accept-Language: ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4,ja;q=0.2

HTTP/1.1 400 Bad Request
Content-Length: 166
Content-Type: text/html; charset=utf-8
Date: Fri, 28 Apr 2017 08:01:03 GMT
Server: nginx
@nijel

This comment has been minimized.

Copy link
Member

@nijel nijel commented Apr 28, 2017

The container will always serve phpMyAdmin on /, you need to rewrite the URL in your reverse proxy.

With haproxy example we have in configuration it is done by reqirep ^(GET|POST|HEAD)\ /phpmyadmin/(.*) \1\ /\2. If you can provide example for traefik we can include it in documentation as well.

@lkaybob

This comment has been minimized.

Copy link

@lkaybob lkaybob commented Apr 28, 2017

Thanks in advance 👍 While I'm looking through docs, and checking timelines of resources when phpMyAdmin is requested, I just want to check one thing. As I said, I get index.php correctly, but when Stylesheet file is requested from index.php, it is requested as following URL.

image

If my assumption is right, there should be /phpmyadmin prefix in above path. Then the process would be like this.

Requesting CSS @ /phpmyadmin/phpmyadmin.css.php to traefik
--> Traefik stripts the prefix /phpmyadmin
--> Forwards the request with path /phpmyadmin.css.php to internal phpMyAdmin server.
--> Respond with stylesheet file

Is my assumption correct?

@lkaybob

This comment has been minimized.

Copy link

@lkaybob lkaybob commented May 2, 2017

Hello again. Sorry for messing up issue thread. I finally found a way to access phpMyAdmin behind traefik. The reason why upper issue happened is a matter of traefik.
Currently, traefik doesn't support backend-by-backend request URL replacement. It merely matches the URL path, or strips the mathed URL path, unlike haproxy or nginx does. (I didn't realize this was a big deal, since traefik is my first reverse proxy experience)

[frontends]
   [frontends.myadmin]
   backend = "myadmin"
   passHostHeader = true
     [frontends.myadmin.routes.default]
     rule="PathPrefixStrip:/phpmyadmin"

I tried 'traefik.toml' first time as above, which is a configuration file. It does get a main page, but static assets, like CSS, JS are not retrieved, since there is no trailing slash on request URL. (This is why above issue happened, browser ommitting incomplete path '/phpmyadmin', when requesting assets.)
So the workaround is to replace whole requested URL, and then strip the prefix. So here is my example for phpMyAdmin behind traefik, with configuration file traefik.toml.

defaultEntryPoints = ["http"]
[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
      regex = "(http:\\/\\/[^\\/]+\\/([^\\?\\.]+)[^\\/])$"
      replacement = "$1/"

[backends]
  [backends.myadmin]
    [backends.myadmin.servers.myadmin]
    url="http://internal.address.to.pma"

[frontends]
   [frontends.myadmin]
   backend = "myadmin"
   passHostHeader = true
     [frontends.myadmin.routes.default]
     rule="PathPrefixStrip:/phpmyadmin/;AddPrefix:/"

P.S. docker-compose.yml(with PMA_ABSOULTE_URI) for starting phpMyAdmin should work with this traefik configuration 😃 . Also, I referenced containous/traefik#563 and containous/traefik#679.

@nijel

This comment has been minimized.

Copy link
Member

@nijel nijel commented May 4, 2017

Thanks, I've added your example to our docs.

nijel added a commit to phpmyadmin/phpmyadmin that referenced this issue May 4, 2017
See phpmyadmin/docker#101 (comment)

Signed-off-by: Michal Čihař <michal@cihar.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.