搜索功能在 localhost 中工作正常但在 VPS 中不工作
Search function working fine in localhost but not in VPS
我的 laravel 网站上有这个搜索功能,它在我的本地主机上运行良好。但是当我使用 git hook 在 vultr vps 中部署它时,搜索功能无法正常工作。
当我点击 localhost 中的搜索按钮时,它会产生一个 url 像这样:http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
但是当部署服务器没有任何反应时,它只是做一些回发负载。
SearchController.php
public function getSearch(Request $request)
{
$this->validate($request, [
'query' => 'required_without_all:keywords,location',
], ['query.required_without_all' => 'Please fill atleast one field.']
);
$query = $request['query'];
$location = $request['location'];
$keywords = $request['keywords'];
if (isset($location) && isset($query) && $keywords) {
$posts = Post::orderBy('created_at', 'desc')->where('title', 'like', '%' . $query . '%')->where('location', 'like', $location)->where('body', 'like', $keywords)->paginate(5);
}
.......
else {
$query = '';
$location = '';
$posts = Post::orderBy('created_at', 'desc')->where('location', 'like', $location)->paginate(5);
}
return view('includes.search-index', ['posts' => $posts]);
}
routes/web.php
Route::get('/search', [
'uses' => 'SearchController@getSearch',
'as' => 'search'
]);
search.blade.php
<form action="{{ route('search') }}" method="get" >
.....
</form>
有什么想法吗?好像请求没有通过?因为我得到一个空请求?
检查 link 在表单操作中创建的内容。如果您的 .env 或配置中有本地主机,则路由可能会创建不正确的 link。否则请查看您的服务器日志。
您也可以在您的控制器中进行调试。和第一次一样 运行,接下来的步骤就是问题所在。
我的 nginx
/etc/nginx/sites-available/default
文件中有错误。
location / {
try_files $uri $uri/ /index.php?query_string;
}
应该是
location / {
try_files $uri $uri/ /index.php?$query_string;
}
我的 laravel 网站上有这个搜索功能,它在我的本地主机上运行良好。但是当我使用 git hook 在 vultr vps 中部署它时,搜索功能无法正常工作。
当我点击 localhost 中的搜索按钮时,它会产生一个 url 像这样:http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw
但是当部署服务器没有任何反应时,它只是做一些回发负载。
SearchController.php
public function getSearch(Request $request)
{
$this->validate($request, [
'query' => 'required_without_all:keywords,location',
], ['query.required_without_all' => 'Please fill atleast one field.']
);
$query = $request['query'];
$location = $request['location'];
$keywords = $request['keywords'];
if (isset($location) && isset($query) && $keywords) {
$posts = Post::orderBy('created_at', 'desc')->where('title', 'like', '%' . $query . '%')->where('location', 'like', $location)->where('body', 'like', $keywords)->paginate(5);
}
.......
else {
$query = '';
$location = '';
$posts = Post::orderBy('created_at', 'desc')->where('location', 'like', $location)->paginate(5);
}
return view('includes.search-index', ['posts' => $posts]);
}
routes/web.php
Route::get('/search', [
'uses' => 'SearchController@getSearch',
'as' => 'search'
]);
search.blade.php
<form action="{{ route('search') }}" method="get" >
.....
</form>
有什么想法吗?好像请求没有通过?因为我得到一个空请求?
检查 link 在表单操作中创建的内容。如果您的 .env 或配置中有本地主机,则路由可能会创建不正确的 link。否则请查看您的服务器日志。
您也可以在您的控制器中进行调试。和第一次一样 运行,接下来的步骤就是问题所在。
我的 nginx
/etc/nginx/sites-available/default
文件中有错误。
location / {
try_files $uri $uri/ /index.php?query_string;
}
应该是
location / {
try_files $uri $uri/ /index.php?$query_string;
}