簡體   English   中英

搜索功能可以在localhost上正常運行,但不能在VPS中運行

[英]Search function working fine in localhost but not in VPS

我在laravel網站中具有此搜索功能,在我的本地主機中可以正常工作。 但是,當我使用git hook在vultr vps中部署它時,搜索功能無法正常工作。

當我單擊本地主機中的搜索按鈕時,它將產生一個類似以下的URL: http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw : http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw : http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw search? http://127.0.0.1:8000/search?query=test&location=&keywords=&_token=I5BDCrqHtdwvsSwrHTrdAAGYfdukPCgU3OAGDySw _ 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]);      
}

路線/ web.php

Route::get('/search', [
    'uses' => 'SearchController@getSearch',
    'as' => 'search'
]);

search.blade.php

<form action="{{ route('search') }}" method="get" >
    .....
</form>

任何想法? 似乎請求沒有通過? 因為我有一個空的請求?

檢查在表單操作中創建了什么鏈接。 如果您的.env或配置中有本地主機,則該路由可能會創建錯誤的鏈接。 否則,請查看您的服務器日志。

您也可以在控制器中調試。 它首先運行,然后在下一步中解決問題。

我的nginx /etc/nginx/sites-available/default文件中存在錯誤。

location / {
            try_files $uri $uri/ /index.php?query_string;
}

它應該是

location / {
            try_files $uri $uri/ /index.php?$query_string;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM