我将Laravel 7用于后端,将Nginx用于服务器,并将flutter用于应用程序。
我使用“让我们加密”和Certbot为服务器安装了SSL层。在使用SSL之前,一切都很好,它可以正常工作。但是安装SSL后,我在flutter上收到了此错误:
HandshakeExceiption:客户端中的握手错误(操作系统 错误:TLSV1_ALERT_PROTOCOL_VERSION(tls_record.cc:587))
这是我的请求代码:
import 'package:package_info/package_info.dart';
import 'dart:io';
import 'package:dio/dio.dart';
import './home.dart';
import './auth.dart';
String token;
class RootProvider {
static Dio http = Dio();
static final baseUrl = "https://my_domain.com/api";
static String locale = '';
static Future<void> setRequestHeaders() async {
token = await AuthProvider.getToken();
String _locale = await HomeProvider.getLocale();
locale = _locale == 'en' ? 'tm' : _locale;
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String platform = "";
if (Platform.isAndroid) {
platform = "android";
} else if (Platform.isIOS) {
platform = "ios";
}
var headers = {
'Accept': 'application/json',
'Content-Type': 'application/json',
'Language': _locale == 'en' ? 'tm' : _locale,
'Version': packageInfo?.version,
'Platform': platform,
};
if (token != null) headers['Authorization'] = "Bearer $token";
http.options.baseUrl = baseUrl;
http.options.headers = headers;
}
static init() async {
await setRequestHeaders();
http.interceptors.add(
InterceptorsWrapper(
onRequest: (RequestOptions options) {
print('Making request to ${options.method} ${options.uri}');
},
onResponse: (Response response) {
// if response successful then return data
if (response.data['success'] == true && response.data['success']) {
return http.resolve(response);
}
return http.reject(response.data['message']);
},
onError: (DioError e) async {
return http.reject(e);
},
),
);
}
}
这是我的Nginx conf:
server {
listen 80;
listen [::]:80;
server_name my_domain.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name my_domain.com;
root /var/www/my_domain/public;
ssl_certificate /etc/letsencrypt/live/my_domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/my_domain.com/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";
index index.php index.html index.htm index.nginx-debian.html;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
}
location ~ /\.ht {
deny all;
}
location ~ /.well-known {
allow all;
}
}
注意:我试图通过Axios发送一个关于javascript的请求,并且得到了成功的响应。它适用于Axios和Javascript。它只对颤动不起作用。
请帮我发现问题。预先谢谢你