I have some PHP pages under /ugly/path/for/php/assets/, but users usually access them from pretty ad hoc locations.
As an example, is a proxy of .
Is there a way to pass "/signup" from Nginx to PHP-FPM and avoid URL redirection when sending a form?

This happens with forms like the following where users click submit from and then read the reply from , because of variable $_SERVER['PHP_SELF'] value.

echo "<form method=\"post\" action=\"".htmlspecialchars($_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING'], ENT_QUOTES)."\" enctype=\"multipart/form-data\">

// What variable returns
// $_SERVER['REQUEST_URI'] = "/ugly/path/for/php/assets/signup"
// $_SERVER['PHP_SELF'] = "/ugly/path/for/php/assets/signup.php" 
// basename(__FILE__) = "signup.php"

Lô đề onlineThis is the actual Nginx config:

location /signup {
 proxy_pass http://example.com/ugly/path/for/php/assets/signup;

location /ugly/path/for/php/assets {
 try_files $uri $uri.php =404;
 include fastcgi.conf;
 real_ip_header X-Real-IP;
 fastcgi_intercept_errors on;
 fastcgi_param SERVER_NAME $host;
 fastcgi_pass unix:/run/php-fpm/php-fpm.sock;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.