1、nodejs Get the real client IP Address :

In the general management website , You need to record some of the user's actions , And remember which user did it , At this time, the user's ip Address , But often when these applications are deployed on the server , It's all used ngix etc.

agent , When the user accesses it , You need to check the user's real life through the agent IP Address , Here are nodejs Get client reality IP Code for :

// Get client reality ip;
function getClientIp(req) {
var ipAddress;
var forwardedIpsStr = req.headers['X-Forwarded-For'];// Determine whether there is reverse proxy header information
if (forwardedIpsStr) {// If there is , Take out the first address in the header information , The address is the real client IP;
var forwardedIps = forwardedIpsStr.split(',');
ipAddress = forwardedIps[0];
}
if (!ipAddress) {// If there is no direct access IP;
ipAddress = req.connection.remoteAddress;
}
return ipAddress;
};

in addition , I saw someone else write like this on the Internet :

// Code , The first paragraph judges whether there is a reverse proxy IP( Header information :x-forwarded-for), In judging connection Remote IP, And the back end socket Of IP.
function getClientIp(req) {
return req.headers['x-forwarded-for'] ||
req.connection.remoteAddress ||
req.socket.remoteAddress ||
req.connection.socket.remoteAddress;
};

2、nodejs Dynamic pages refer to content in static paths

Reference the content under the static introduction path in the dynamic page ( Such as images ,css When you file ), Pay attention to the way the path is written :

for example : I am here error.html I quote “public/images/” Under the error.png picture , It takes a few steps :

The structure of the project :

First step :app.js in :

app.use(express.static(path.join(__dirname, 'public')));// Indicates that a dynamic page can be referenced public Static information under the path 

The second step :error.html in :

stay style in , When quoting a background picture , You can't add more before the path “public/”, Only for :“images/error.png”, Because in app.js The dynamic page can only be referenced in public Static content under , And by default it's in public Under the path , Just write from public It's OK to start writing the lower level directory of .

 <!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width initial-scale=1.0 maximum-scale=1.0 user-scalable=no" />
<title> Unified payment </title>
<style>
.error-404{background-color:#EDEDF0;}
section{display: block;}
.clearfix{zoom:1;}
.module-error{margin-top:182px;}
.module-error .error-main{ margin: 0 auto;width: 420px;}
.module-error .label{float: left;width: 160px;height: 151px;background: url("images/error.png") 0 0 no-repeat;}// The default is already in public Under the path , Even though the code changes in IDE Error reported in ( Don't worry about it )
.module-error .info{ margin-left: 182px;line-height: 1.8;}
.module-error .title{color: #666;font-size: 14px;}
.module-error .reason{margin: 8px 0 18px 0;color: #666;font-size: 12px;}
</style>
</head>
<body class="error-404">
<div id="doc_main">
<section class="bd clearfix">
<div class="module-error">
<div class="error-main clearfix">
<div class="label"></div>
<div class="info">
<h3 class="title"> Ah! , The page you visited no longer exists .</h3>
<div class="reason">
<p> Probable cause :</p>
<p>1. Wrong address entered in the address bar .</p>
<p>2. A link you click on has expired .</p>
</div>
<div class="oper">
<p><a href="/"> Back to the front page &gt;</a></p>
<p class="reason"> or 10s After that, it will automatically jump to the home page </p>
</div>
</div>
</div>
</div>
</section>
</div>
<script>
setTimeout("window.location.href='/'",10000);
</script> </body>
</html>

error.html

nodejs To get the real ip Address + Dynamic page refers to the static path of files and pictures and other content of more related articles

  1. 【Go】 Get the user's real ip Address

    Link to the original text :https://blog.thinkeridea.com/201903/go/get_client_ip.html There are many links between the user's request and the server providing the service , Cause the service to get the user's real ip ...

  2. Get the client's request IP Address

    Get the client's request IP Address package com.microClass.util; import javax.servlet.http.HttpServletRequest; import java. ...

  3. use Java To get the real IP Address

    use Java To get the real IP Address Reprint 2016 year 06 month 07 Japan 14:36:02 label : 16497 edit Delete stay JSP in , Get client's IP The way to get an address is :request.getRemoteAdd ...

  4. JAVA_ use Java To get the real IP Address

    stay jsp in , Get client's ip The way to get an address is :request.getRemoteAddr(), This approach works in most cases . But it passed Apache,Squid And so on reverse proxy software cannot obtain the client's real I ...

  5. java Get visitors' real IP Address

    as everyone knows java Method request.getremoteaddr() You can get visitors IP Address But it passed Apache,Squid And so on reverse proxy software cannot obtain the client's real IP Address . If reverse proxy software is used ...

  6. PHP Get client and server IP Address

    /** * Get the client IP Address * @return string */ function get_client_ip() { if(getenv('HTTP_CLIENT_IP')){ $client ...

  7. Lodop Get the main network card of the client ip The address is 0.0.0.0

    LODOP Technical manual GET_SYSTEM_INFO piece ,LODOP You can use statements to get a lot of client information ,NetworkAdapter.1.IPAddress It's the main network card IP Address , Usually it's ok , But if at present ...

  8. F5 Source address translation (AutoMap) Mode, the back-end server gets the real IP Address

    F5 In the open AutoMap, And transmission X-Forwarded-For value Turn on F5 Source address translation "Auto Map" Mode one :  stay http profile In the open X-Forwarded-For ...

  9. Nginx The reverse proxy gets the real IP Address

    package com.das.common.util; import org.apache.commons.lang3.StringUtils; import org.springframework ...

Random recommendation

  1. Could not resolve placeholder Solution

    spring Configuration is loaded properties When you file , newspaper Could not resolve placeholder error . After a careful search , Exclude file paths , The reason for the file class error , After searching for relevant information , appear &q ...

  2. Struts2 Source code analysis —— The core mechanism

    MVC And the three-tier view Through the last chapter, we understand the knowledge points and goals we need to learn . So in this chapter I'm going to talk about users struts2 The mechanism and principle of . We all know that struts2 The core idea of MVC thought .MVC The full name is Model View ...

  3. EasyUI datagrid Optimize

    easyui datagrid stay IE Loading speed is slow , 150 Row data is unbearable . firefox The loading speed is OK . jquery easyui datagrid The use of reference http://www.cnblo ...

  4. 【leetcode】 Generate Parentheses (middle)*

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  5. Spring Annotate non database field properties in entity classes

    terms of settlement : In attribute get Method with an annotation to indicate that it is a temporary property , Not database fields OK @Transient public List<Reverts> getChildList() { retu ...

  6. JAVA introduction [22]—thymeleaf

    One .thymeleaf Official website Official website :https://www.thymeleaf.org/index.html doc:https://www.thymeleaf.org/documentation.ht ...

  7. Python The road to growth 【 Third articles 】 function

    function One . background Before learning functions , Always follow : Process oriented programming , namely : Implement functions from top to bottom according to business logic , It often uses a long piece of code to achieve the specified function , The most common operation in the development process is paste copy , That is to copy the previously implemented code block to the current function ...

  8. Windows PowerShell Introduction (3)-スクリプト Edit

    これまでの article Windows PowerShell Introduction (1)- Basic operation Windows PowerShell Introduction (2)- Basic operation 2 To the elephant Windows PowerShellでコマンド ...

  9. apache utilize http_referer Carry out the anti-theft chain

    http://blog.sina.com.cn/s/blog_8729dd9801011rn1.html

  10. java Connect zookeeper The server appears “KeeperErrorCode = ConnectionLoss for ...”

    The error message is as follows : Exception in thread "main" org.apache.zookeeper.KeeperException$ConnectionLossExce ...