'Encrypting IPv4 address with NGINX as reverse proxy

For a research project I have a Flask application running on an AWS EC2 instance with nginx as reverse proxy. My goal is to encrypt the visiting clients' IPv4 address in nginx and pass it through to the Flask application, which will be able to decrypt the data. I do this, to avoid using the clients' IP address as plain text, which would violate upcoming changes to GDPR compliance (which my research is about).

As far as I know, there is no way of achieving this by modifying the nginx.conf file, so I cloned nginx' source code to encrypt the data directly in the code responsible for receiving and forwarding the clients' IP. Unfortunately, I'm not very good at C programming and finding the right parts of the code, that I would have to change, seems fairly impossible to me.

Does anyone have an easy example of changing a header variable directly in the source code and passing it through the nginx reverse proxy to a Flask (or similar) application?

Thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source