I
I
iiiiiiiaaa2021-09-09 05:37:39
PHP
iiiiiiiaaa, 2021-09-09 05:37:39

How to intercept php requests in nginx?

I have a simple flask application for buying goods, to integrate the CDEK pickup widget, you need to place a php file on the server, a link to which must be specified in the js script, an example (from the CDEK documentation):

<script type="text/javascript">
    var ourWidjet = new ISDEKWidjet ({
        ...
        servicepath: 'http://yoursite.net/service.php', //ссылка на файл service.php на вашем сайте
        ...
    });
</script>


At the moment I have no way to rewrite the logic of this script in python, so I thought to just leave it as it is, QUESTIONS:

1. How can I configure my nginx so that when this path is requested, the server does not send it to gunicorn-flask for processing , but independently executed php and returned the desired response?
2. I read that you can run php directly from python through subprocess, but I doubt the correctness of such a decision.
3. Is there a simpler / ready-made solution?

My current nginx config (/etc/nginx/sites-available/myproject):
server {
    server_name yoursite.net www.yoursite.net;

    location / {
        include proxy_params;
        proxy_pass http://unix:/home/user/myproject/project.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/yoursite.net/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/yoursite.net/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = www.yoursite.net) {
        return 301 https://yoursite.net$request_uri;
    } # managed by Certbot

    if ($host = yoursite.net) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

    listen 80;
    server_name yoursite.net www.yoursite.net;
    return 404; # managed by Certbot
}


Thanks in advance to anyone who spends their time here!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
ky0, 2021-09-09
@ky0

How can I configure my nginx so that when this path is requested, the server does not send it to gunicorn-flask for processing, but executes php itself and returns the desired response?

Just add a location with this url and the corresponding processing.
https://nginx.org/ru/docs/http/request_processing.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question