Client IP processing in Odoo anti-agent

Source: Internet
Author: User

* 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.