nginxreverse-proxyphpredis

Nginx Reverse Proxy settings


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

Now when I browse to `https://example.com/admin/redisadmin/index.php'

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

<form action="/redisadmin/edit.php?s=0" method="post">

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

https://example.com/redisadmin/edit.php?s=0

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

<form action="/admin/redisadmin/edit.php?s=0" method="post">

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.


Solution

  • 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.