Nginx Reverse Proxy settings


Nginx Reverse Proxy settings

I am in the process of setting up a server configuration which consists of

A front end server running Nginx. Call it
Another server, also running Nginx, (on the same network and accessible via an internal IP, say which runs – amongst other things – phpRedisAdmin.
The front end server has a reverse proxy configuration that goes like this
location ^~ /admin/ {

Now when I browse to `’
The Memcache Admin page turns up just right. An examination of console logs shows now errors. I then proeed to click the Add Another Key link which brings up the phpMemcachedAdmin edit form. When I examine the code for this form I see

Now if I enter a key name, a value and click on the Add button in the form the browser attempts to post to

which promptly throws up a 404 since the action URL for the form should in fact have been

Somewhere along the way the /admin bit got lopped off. I suspect that this is down to invalid Nginx reverse proxy settings. However, I am a novice when it comes to this so I have no idea how I should correct the problem. I would much appreciate any help.


Solution 1:

Have checked the page of redis admin and found it reads the request URI from server side, which means it will include the leading slash ‘/’ in the URL for the post form:

<form action="<?php echo format_html($_SERVER['REQUEST_URI'])?>" method="post">

You have the remove the leading slash in php so you can post to correct address when access via reverse proxy. However, as a workaround, you can rewrite the URL in nginx to fix it.

location / {
    rewrite ^/redisadmin/(.*)$ /admin/redisadmin/$1 last;

Add the above rewrite rule to your setting in ‘/’ seciton, see if it works.

Solution 2:

As @Johnnie Zhang has pointed out the root of the issue here was the leading / which resulted in the post action being treated as an absolute path. However, after a bit of investigation I have concluded that although phpredisadmin is an excellent all-round option when used as a standalone Redis web GUI it is liable to be pose too many problems when used via a reverse proxy.