Home > PHP Framework > Laravel > Analyze the interface communication problem between internal servers from two aspects

Analyze the interface communication problem between internal servers from two aspects

藏色散人
Release: 2022-11-21 17:19:53
forward
1090 people have browsed it

In actual business, there are often interface communications between internal servers, which involves two aspects: first, bandwidth, and second, security.

Analyze the interface communication problem between internal servers from two aspects

1. Intranet transmission

We know that intranet transmission does not occupy server bandwidth and is faster than external network transmission. If The requested interface address is https://api.xxx.com/userinfo. To achieve intranet transmission, edit the local /etc/hosts file

api.xxx.com 10.0.123.1 # 内网ip
Copy after login

2. Security

For providing interfaces For api.xxx.com, it is relatively simple to limit the source of requests, using the key IP whitelist. [Recommended: laravel video tutorial]

Using laravel as an example, create a middleware App\Http\Middleware\Remind.php

public function handle($request, Closure $next)
{
  $key = $request->input('key', '');
  if (
    $key != 'abc'
    || !in_array($request->ip(), ['10.0.123.2'])
  ) {
    return response()->json([
      'code' => 403,
      'msg' => 'access error',
    ], 403);
  }
  return $next($request);
}
Copy after login

Original author: php_yt

Redirected from the link: https://learnku.com/articles/73351

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of Analyze the interface communication problem between internal servers from two aspects. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:learnku.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template