【发布时间】:2019-12-20 06:24:47
【问题描述】:
目前我已经成功设置了我的Laravel Passport API
使用Laravel 5.8。
我的 api 有这个 httpd-vhosts.conf 配置
端口:80
<VirtualHost *:80>
ServerName <sub-domain>.<domain>.com
ServerAlias <sub-domain>.<domain>.com
Redirect permanent / https://<sub-domain>.<domain>.com
</VirtualHost>
端口:443
<VirtualHost *:443>
DocumentRoot "/opt/lampp/htdocs/api_tk/public"
<Directory "/opt/lampp/htdocs/api_tk/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerName <sub-domain>.<domain>.com
ServerAlias <sub-domain>.<domain>.com
ErrorLog "logs/API-error_log"
CustomLog "logs/API-access_log" common
ProxyPreserveHost On
ProxyRequests Off
ProxyPassMatch /fingerprint http://localhost:5000
ProxyPassReverse /fingerprint http://localhost:5000
RequestHeader set X-Forwarded-Proto https
RequestHeader set X-FOrwarded-Port 443
SSLEngine on
SSLCertificateFile "/opt/lampp/htdocs/ssl_key/svs-file.crt"
SSLCertificateKeyFile "/opt/lampp/htdocs/ssl_key/private_new.key"
SSLCACertificateFile "/opt/lampp/htdocs/ssl_key/svs-bundle-file.crt"
</VirtualHost>
443 工作正常,我可以在浏览器上看到我的 HTTPS SSL 锁定标志
但是
当我尝试做 HTTP 请求时
Laravel API 总是被毁掉。
我有这样的路线
https://..com/api/login
这很好用
但是当我尝试像这样进行 HTTP 请求时
http://<sub-domain>.<domain>.com/api/login
它总是以
https://<sub-domain>.<domain>.comapi/login
斜线缺失的地方。这是因为我的 PORT 80 配置上的 redirect permanent。
我的 api 有这条路线。 (api.php)
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::post('/timekeeping','Auth\Api\AuthController@timekeeping');
Route::post('/login','Auth\Api\AuthController@login');
Route::middleware('auth:api')->group(function () {
Route::post('/timekeeping_app','Auth\Api\AuthController@timekeeping_app');
Route::post('/logout','Auth\Api\AuthController@logout');
Route::post('/register','Auth\Api\AuthController@register');
Route::post('/show_dtr_list','Auth\Api\AuthController@show_dtr_list');
Route::post('/update','Auth\Api\AuthController@update');
Route::post('/delete','Auth\Api\AuthController@delete');
Route::post('/search_user','Auth\Api\AuthController@search_user');
Route::get('/current_time','Auth\Api\AuthController@current_time');
});
如何防止这种情况发生?
更新
试图像这样编辑我的虚拟主机配置
Redirect permanent "/" "https://<sub-domain>.<domain>.com/"
和
Redirect permanent / https://<sub-domain>.<domain>.com\/
但这给了我这样的输出
【问题讨论】:
-
两种选择: 1. 尝试添加斜杠并引用网址
Redirect permanent "/" "https://<sub-domain>.<domain>.com/";或 2. 尝试用反斜杠转义斜杠:Redirect permanent / https://<sub-domain>.<domain>.com\/ -
这行得通,它重定向到 https 并到达我的 api 项目,但问题是如果我尝试执行这 2 个选项,这会给我这样的输出
https://<sub-domain>.<domain>.com//api/login包含额外的斜杠,但它应该是https://<sub-domain>.<domain>.com/api/login
标签: laravel api xampp laravel-passport