Reverse proxy on Express

34 Views Asked by At

I am trying to set up a reverse proxy in order to serve PhpMyAdmin at http://localhost/phpmyadmin endpoint.

Unfortunately I've only managed to redirect index.php, any other resource requested by the page is sent directly to http://localhost/, which of course doesn't work.

Here is one of my attempts.

const { createProxyMiddleware } = require('http-proxy-middleware');

// Define a proxy for phpMyAdmin
const phpMyAdminProxy = createProxyMiddleware('/phpmyadmin', {
    target: 'http://admin/', // using the container's name
    changeOrigin: true,
    pathRewrite: {
        '^/phpmyadmin/': '',
    }
    onProxyReq: (proxyReq, req, res) => {
        proxyReq.setHeader('X-Real-IP', req.ip);
        proxyReq.setHeader('X-Forwarded-For', req.ip);
        proxyReq.setHeader('Host', req.headers.host);
    },
});


app.use('/phpmyadmin', phpMyAdminProxy);

I have this line in config.user.inc.php, config.inc.php, and for the PMA_ABSOLUTE_URIenvironment variable, although changing this didn't seem to have any effects.

$cfg['PmaAbsoluteUri'] = 'http://admin/';

I also would like to do this with Matomo, but I have the same problem.

I am considering giving up and putting everything behind NGIX instead, but one fewer container would be great too.

0

There are 0 best solutions below