* Preface
In general, we deploy with Nginx as the front-end processing, sometimes the load will also use other Web service anti-proxy
Only the Nginx processing method is given here, and the other reference processing
* Customer IP Transfer on Nginx
In the server module, add
server{
...
Location/{
...
Proxy_set_header Host $host;
Proxy_set_header X-real-ip $remote _addr;
Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;
...
}
...
}
For X-real-ip is actually the head package inside the parameter key, the corresponding value $remote_addr this is IP
For x-forwarded-for to solve multi-layer anti-proxy IP pass, it is an array, if a layer of anti-proxy, the first
The key value is the customer IP, which is the same as X-REAL-IP, if two tiers, the first is the customer IP second number is the previous one
The IP of the server
I only use the Nginx one layer agent, only use the X-REAL-IP
* Odoo above get customer IP
From openerp.http Import Request
Client_ip=request.httprequest.headers.get (' X-real-ip ', request.httprequest.remote_addr)
Request is an object variable in the openerp/http.py
Request.httprequest This gets the encapsulated object of the Werkzeug request object a wrapped Werkzeug request object
Request.httprequest.headers get the head packet data
You can set the Access-control-allow-methods value to POST using a set method such as Headers.set (' access-control-allow-methods ', ' post ')
Here you want to add a key to the head, right here.
We use here is Headers.get (' KeyName ') here KeyName is used ' X-real-ip '
Have time to print request.httprequest.headers This is a list of header packages that you can see which keys are available
For the back of that request.httprequest.remote_addr, is the default value is normally uploaded to the Odoo service when the IP is extremely likely to be 127.0.0.1
* Use X-FORWARDED-FOR for multi-layer agents
From openerp.http Import Request
If ' x-forwarded-for ' in request.httprequest.headers:
CLIENT_IP = Request.httprequest.headers.get ("x-forwarded-for") [0] or REQUEST.HTTPREQUEST.REMOTE_ADDR
* Extended
You can also use GeoIP to get a lot of information based on IP
Client IP processing in Odoo anti-agent