PHP obtains the real IP address, even if it uses a proxy
[PHP] code
Function getRealIpAddr ()
{
If (! Empty ($ _ SERVER ['http _ CLIENT_IP '])
{
$ Ip = $ _ SERVER ['http _ CLIENT_IP '];
}
Elseif (! Empty ($ _ SERVER ['http _ X_FORWARDED_FOR '])
// Check if the
Recently our PHP website wanted to get the player's IP through a simple $_server["REMOTE_ADDR") unexpectedly get to 127.0.0.1 IPBecause our website is through Nginx Proxy, think of possible to get the player's IP a bit different itSee the $_server[' http_x_forwarded_for ' through this, I changed the code to have no effectDoes not seem to pass over, and then the I
Recently do Bo friend recommended, found a small problem, with $_server[' REMOTE_ADDR ']; are the server's address 192.168.96.52, search for a bit, found the problem, to $_server[' http_x_real_ip '];: nginx proxy mode, get client real IP
Set in Nginx:
Proxy_set_header Host $host;Proxy_set_header X-real-ip $remote _addr;Proxy_set_header x-forwarded-for $
code.If yes, find out its representative characters. For example, a constant of define.The next step is to find a file with the same characteristics in the same way as above.Second, use Nginx to do reverse proxyFirst on the code:Location/ { proxy_redirect off; Proxy_set_header Host $host; Proxy_set_header X-real-IP $remote _addr; Proxy_set_header X-forwarded-for $proxy
Issue background:Before our company due to DDoS attacks caused by network exports, after understanding, traffic into the Amazon is no money, and unlimited traffic, in order to strengthen the protection of network attacks on the business impact, in the Amazon to deploy a set of Haproxy agent, the part of the business migration trial.650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/83/1F/wKioL1drZeyxEL5mAAA1K9OBwBc668.png-wh_500x0-wm_3 -wmp_4-s_1612962770.png "title=" Aws-lvs-nginx.png "
Today for the first time with nginx load balancing, found PHP can not get http_hostThe attached nginx configurationUpstream ABC. com { 10.141.8.55:8005; 10.141.8.55:8006;} server { a; server_name www. xxx. com; Log_not_found off; Access_log /var/log/nginx/html-access. Log main; CharSet UTF-8; / { proxy_pass http://abc.com; }}echo $_server[' Http_host '];Output abc.comCarefully look at the Nginx configuration, it
$fastcgi_path_info; includeFastcgi_params; } #再解析PHP, there will be a parsing error like 500}By the way, another CI under the nginx jump rule (because Nginx does not support multi-conditional judgment, the variable is judged):Set$ci0;if(!-f$request _filename) {Set$ci"${ci}a";}if(!-d$request _filename) {Set$ci"${ci}b";}if($uri!~ "^ (index.php|images|robots.txt)") {Set$ci"${ci}c";}if($ci= "0ABC") {rewrite^/(. *) $/index.php/$1Last ;}There is a picture of the truth:The implementation of the
Experimental purposes:
Verify the difference between the default route next hop and the IP on the end.
Experiment topology:
Configuration:
R1:
Interface fastethernet0/0IP address 123.1.1.1 255.255.255.0!IP Route 0.0.0.0 0.0.0.0 fastethernet0/0
R2:
Interface fastethernet0/0IP address 123.1.1.2 255.255.255.0!Interface FASTETHERNET0/1IP address 24.1.1.2 255.255.255.0
R3:
Interface fastethernet0/0IP
In PHP, we generally use $ _ server ['HTTP _ host'] to obtain the domain name or IP address of the website in the URL.The explanation in the PHP manual is as follows:
"Http_host": the host of the current request: the content of the header information.
In general, this will not cause any problems. In some common PHP frameworks, such as pfc3 and flea are also based on this predefined variable.
However, when a program is handed over to the customer fo
a decimal, add 1, not a decimal. Returns the number of pages directlytole_page = Int (page) + 1returnTole_pageElse: Tole_page=int (page)returnTole_pagedefGet_job_message (data):#get work information for each pagehtml = requests.post (url,headers=headers,data=data,proxies =ProX)ifHtml.status_code = = 200:#Show Status CodeJson_data =json.loads (html.text) job_messages= json_data['content']['Positionresult']['result'] forJob_messageinchJob_messages:company= job_message['Companyfullname']#C
Configure nginx reverse proxy Apache for different ports with the same IP address (that is, nginx jumps to Apache)
Nginx and Apache have been installed in a Linux environment since the default port is 80.
Generally, the server port requested by the customer is 80 by default. Therefore, nginx serves as the static page port and is set to 80.
Set the Apache port to 8080 (modify listen: 8080 In the httpd. con
This example of this article has shared the check Agent IP validity PHP code, stability, such as error rate and query usage
/** +-----------------------------------------------------------------------------* Check Agent IP information validity +----------------- ------------------------------------------------------------* @param string $proxy _ip [117.95
C #: The WebBrowser control sets the proxy IP address to access the website [with source code ],Download Software source code
Http://download.csdn.net/detail/php_fly/8041731
In the C language, what is the symbol (->) and how to use it?
This is a symbol in the struct pointer. Write a program to explain it, for example:# Include Struct STU // define a struct{Int num;} Stu;Int main (){Struct STU * p; // define
1) Modify the Haproxy configuration file and add the following parameters:Option Httpcloseoption forwardfor2) Modify the Nginx configuration file, add the following parameters Note: You need to compile the module--with-http_realip_module#haproxy服务器IPset_real_ip_from 192.168.64.128;real_ip_header x-forwarded-for;real_ip_recursive on;3) Restart Haproxy and Nginx respectively/etc/init.d/haproxy Restart/etc/init.d/nginx RestartThis article is from the "ˉt, Stand Wentao ┃﹎" blog, please be sure to ke
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.