Home > database >  Receiving http request with php script (from nginx proxy pass)
Receiving http request with php script (from nginx proxy pass)

Time:01-10

I'm trying to use data sent by nginx's proxy_pass directive in a php script.

Normally this is done with a proper web server, but I thought this might be a simpler and more reliable approach for very basic use cases.

This is the relevant nginx configuration:

location ~ \.htm$ {
    post_action /test;
    }

location = /test {
    internal;
    proxy_method POST;
    proxy_pass https://some.website/test.php;
    }

This is the php script:

<?php

$headers = getallheaders();
$useragent = $headers['User-Agent'];
$languages = $headers['Accept-Language'];
$md5 = md5($useragent   $languages);
$endpoint = "https://some.webserver/endpoint";
$ch = curl_init($endpoint);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $md5);
curl_exec($ch);
curl_close($ch);

So, the intended functionality is that whenever a .htm page is loaded, the data is proxy_passed to some.website, processed and then sent further to some.webserver.

This doesn't seem to work... however:

  1. If I use Postman to send a Post request to https://some.website/test.php, it works.

  2. If I proxy_pass directly to https://some.webserver/endpoint, it works.

So what am I missing?

CodePudding user response:

Turns out it was a ssl issue, adding proxy_ssl_server_name on; to the nginx block fixed it.

  • Related