A
A
Andrei Smirnov2017-08-23 13:34:07
PHP
Andrei Smirnov, 2017-08-23 13:34:07

How to proxy all HTTP requests through your server?

The task is this: my site has an nginx server, let's call it mysite , and there is another server that provides some HTTP API, let's call it httpapi . In order not to do CORS for other reasons, you need to proxy all HTTP requests from the client to httpapi through mysite .
For example it will look like this:

// get products API
POST https://httpapi.com/get_products

fetch('/proxy/get_products', {
     method: "POST",
     body: params
  };

Here, everything behind /proxy should be transformed into httpapi calls. Should work over HTTPS for GET and POST requests.
There is php on mysite, you can apparently do it in php with curl, and also set up .htaccess.
Question - is there such a ready-made solution and where to peep it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
PrAw, 2017-08-23
@pinebit

server {
        listen 80;
        server_name my.proxy.ru;
        location /proxy {
                rewrite ^/proxy/(.*) /$1;
                proxy_pass http://kuda.nado.ru;
        }
}

upd: forgot rewrite to cut off /proxy/

A
Andrei Smirnov, 2017-08-27
@pinebit

As a result, we could not configure mod_proxy due to cpanel features, but to be honest, we didn’t really try.
Went the other way and I made a simple php script that makes a proxy. If it will be useful to someone - posted it on github:
https://github.com/pinebit/http-request-proxy

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question