简体   繁体   中英

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

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM