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

Analyze the interface communication problem between internal servers from two aspects

藏色散人
藏色散人 forward
2022-11-21 17:19:53 982browse

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

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); }

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!

Statement:
This article is reproduced at:learnku.com. If there is any infringement, please contact admin@php.cn delete