XtReLL
@XtReLL

Маршрутизация Laravel + AngularJS Nginx. Как настроить запросы?

Здравствуйте. Есть веб сервер с веб-обработчиком Nginx. Бекенд - laravel, Фронт - AngularJS.
Роутусы laravel устроены так. Общение с AngularJS через "/api", С простыми запросами "/'
Вот сам файл
Роутусы
<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function() {
	View::addExtension('html', 'php');
	return View::make('index');
});


Route::group(['prefix' => '/api'], function () {
	Route::get('/auth/login', 'AuthController@redirectToSteam');
    Route::get('/auth/handle', 'AuthController@handle');
    Route::get('/auth/logout', 'AuthController@logout');
	Route::post('/payapi/pushback', 'PaymentController@getPaymentSkin');
	Route::post('/sci/checkout', 'PaymentController@getPaymentSum');
    Route::post('/getUser', 'UserController@get');
    Route::post('/getCases', 'CasesController@get');
    Route::post('/getCase', 'CasesController@getOneCase');
    Route::post('/openCase', 'CasesController@open');
    Route::post('/updateBalance', 'UserController@updateBalance');
    Route::post('/getLiveDrop', 'CasesController@getLiveDrop');
    Route::post('/getStatistic', 'CasesController@getStatistic');
    Route::post('/sell', 'CasesController@sell');
    Route::post('/profile', 'UserController@profile');
    Route::post('/saveTradeLink', 'UserController@saveTradeLink');
    Route::post('/getTop', 'UserController@getTop');
    Route::post('/getProfilePartner', 'UserController@getPartner');
    Route::post('/getInvite', 'UserController@getInvite');
    Route::post('/getMyCode', 'UserController@getMyCode');
    Route::post('/withdrawItem', 'BuyController@withdrawItem');
    Route::post('/withdrawStatus', 'BuyController@withdrawStatus');
    Route::post('/setOfferID', 'BuyController@setOfferID');
    Route::post('/withdrawStatusOffer', 'BuyController@withdrawStatusOffer');
    Route::post('/pushNewItems', 'BuyController@pushNewItems');
    Route::post('/payment/sumPayment', 'PaymentController@sumPayment');
    Route::post('/payment/sumSkins', 'PaymentController@sumSkins');
    Route::post('/checkStatus', 'BuyController@checkStatus');
    Route::post('/checkBuyItems', 'BuyController@checkBuyItems');
	Route::post('/getTrades', 'CasesController@trades');
	Route::post('/promoItem', 'CasesController@promoItem');
	
Route::group(['middleware' => 'access'], function () {
        Route::get('/admin/stats', 'Admin@stats');
        Route::get('/admin/stats/case', 'Admin@statscase');
        Route::get('/admin/stats/users', 'Admin@statsusers');
        Route::get('/admin/items', ['as' => 'items', 'uses' => 'Admin@items']);
        Route::get('/admin/items/delete/{id}', ['as' => 'items', 'uses' => 'Admin@itemsdel']);
        Route::get('/admin/itemsban', ['as' => 'itemsban', 'uses' => 'Admin@itemsban']);
        Route::get('/admin/search', ['as' => 'search', 'uses' => 'Admin@search']);
        Route::get('/admin/searchusers', ['as' => 'search', 'uses' => 'Admin@search2']);
        Route::get('/admin/users', ['as' => 'users', 'uses' => 'Admin@users']);
        Route::get('/admin/user/{id}', ['as' => 'users', 'uses' => 'Admin@userid']);
        Route::get('/admin/lastmoney/{id}', ['as' => 'lastmoney', 'uses' => 'Admin@lastmoney']);
        Route::match(['get', 'post'], '/admin/givemoney/{id}', ['as' => 'givemoney', 'uses' => 'Admin@givemoney']);
        Route::match(['get', 'post'], '/admin/edit/{id}', ['as' => 'cases', 'uses' => 'Admin@itemsedits']);
        Route::match(['get', 'post'], '/admin/userdit', ['as' => 'user', 'uses' => 'Admin@userdit']);
        Route::get('/admin/items/cat/{id}', ['as' => 'items', 'uses' => 'Admin@itemscat']);
        Route::get('/admin/case/{id}', ['as' => 'cases', 'uses' => 'Admin@casesid']);
        Route::get('/admin/items/{id}', ['as' => 'cases', 'uses' => 'Admin@itemsid']);
        Route::get('/admin/itemsnew', ['as' => 'cases', 'uses' => 'Admin@itemsnew']);
        Route::get('/admin/cases', ['as' => 'cases', 'uses' => 'Admin@casesnew']);

        /*Prizes*/
        Route::get('/admin/prize', 'Admin@prizes');
        Route::get('/admin/prize/add', 'Admin@addingprize');
        Route::get('/admin/prize/edit/{id}', 'Admin@prizeid');
        Route::get('/admin/prize/delete/{id}', 'Admin@delete');

        Route::match(['get', 'post'], '/admin/prize/new', 'Admin@prizeadd');
        /*Prizes*/

        /*GROUPS*/
        Route::get('/admin/groups', 'Admin\GroupsController@index');
        Route::get('/admin/groups/add', 'Admin\GroupsController@addView');
        Route::get('/admin/groups/edit/{id}', 'Admin\GroupsController@editView');
        Route::get('/admin/groups/delete/{id}', 'Admin\GroupsController@delete');

        Route::match(['get', 'post'], '/admin/groups/new', 'Admin\GroupsController@add');
        Route::match(['get', 'post'], '/admin/groups/edit', 'Admin\GroupsController@edit');
        /*GROUPS*/

        Route::match(['get', 'post'],'/admin/casesedit', ['as' => 'cases', 'uses' => 'Admin@casesedit']);
        Route::match(['get', 'post'],'/admin/itemsedit', ['as' => 'cases', 'uses' => 'Admin@itemsedit']);
        Route::match(['get', 'post'],'/admin/config', ['as' => 'config', 'uses' => 'Admin@config']);
        Route::match(['get', 'post'],'/admin/clearstats', 'Admin@clearstats');
        Route::match(['get', 'post'],'/admin/deletegames', 'Admin@deleteGames');
        Route::get('/admin322', ['as' => 'admin', 'uses' => 'Admin@index']);
        Route::get('/admin/case', ['as' => 'cases', 'uses' => 'Admin@cases']);
        Route::get('/admin/log', ['as' => 'log', 'uses' => 'Admin@autobuy']);
        Route::get('/admin/game', ['as' => 'game', 'uses' => 'Admin@game']);
        Route::get('/admin/inventory', 'Admin@loadInventory');
        Route::get('/admin/config', ['as' => 'config', 'uses' => 'Admin@config']);
        Route::get('/listbuy', ['as' => 'cases', 'uses' => 'Sell@listbuy']);
        Route::get('/listupdate', ['as' => 'cases', 'uses' => 'Sell@listupdate']);
        Route::get('/admin/transactions', 'Admin@transactions');
        Route::get('/admin/skinpay', 'Admin@skinpay');
        Route::get('/admin/useritems', 'Admin@userItems');
        Route::get('/admin/listbuy', ['as' => 'cases', 'uses' => 'Sell@listbuy']);
        Route::get('/admin/delay', 'Admin@indexDelay');
        Route::match(['get', 'post'],'/admin/nullitem', 'Admin@nullItem');
        /********** TABLE ROUTES *********/

        Route::get('/admin/table/stat', 'Admin\StatsController@stat');
        Route::get('/admin/table/our', 'Admin\StatsController@our');
        Route::get('/admin/table/advert', 'Admin\StatsController@advert');
        Route::get('/admin/table/calendar', 'Admin\StatsController@calendar');

        Route::get('/admin/table/stat/add', 'Admin\StatsController@statForm');
        Route::get('/admin/table/our/add', 'Admin\StatsController@ourForm');
        Route::get('/admin/table/advert/add', 'Admin\StatsController@advertForm');

        Route::match(['get', 'post'],'/admin/table/stat', 'Admin\StatsController@addStat');
        Route::match(['get', 'post'],'/admin/table/our', 'Admin\StatsController@addOur');
        Route::match(['get', 'post'],'/admin/table/advert', 'Admin\StatsController@addAdvert');

        Route::match(['get', 'post'],'/admin/table/stat/del', 'Admin\StatsController@delStat');
        Route::match(['get', 'post'],'/admin/table/our/del', 'Admin\StatsController@delOur');
        Route::match(['get', 'post'],'/admin/table/advert/del', 'Admin\StatsController@delAdvert');
        Route::get('/admin/table/advert/change/{id}', 'Admin\StatsController@changeAdvertView');
        Route::match(['get', 'post'],'/admin/table/advert/change', 'Admin\StatsController@changeAdvert');
        //Route::get('/newdemo', ['as' => 'newgdemo', 'uses' => 'Demo@newgame']);
        // Route::get('/newgame', ['as' => 'newgame', 'uses' => 'Games@newgame']);

        Route::get('/admin/codes', 'Admin@Codes');
        Route::get('/admin/codes/add', 'Admin@addCode');
        Route::post('/admin/codes/add', 'Admin@addCodePost');
        Route::get('/admin/codes/delete/{id}', 'Admin@deleteCode');
    });

	
});
Route::get('/home', function () {
  View::addExtension('html', 'php');
	return View::make('index');
});



А вот конфиг Nginx
конфиг Nginx
server {
listen 80;
server_name candy-cases.com www.candy-cases.com;
access_log /var/log/access.log;
error_log /var/log/error.log;
rewrite_log on;
root /var/www/candy-cases.com/public;
index index.php index.html;
location / {
	index index.php;
	try_files $uri $uri/ /index.php?$query_string;
	#expires -1;
        #add_header Pragma "no-cache";
        #add_header Cache-Control "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
        #try_files $uri $uri/ /index.html ;
   	#rewrite ^(.*)$ /index.html;
}

if (!-d $request_filename) {
	rewrite ^/(.+)/$ /$1 permanent;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}

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

location ~* \.(?:ico|css|js|jpe?g|JPG|png|svg|woff)$ {
expires 365d;
}


}



Но проблема в том, что мой конфиг вроде бы нормально обрабатывает запросы с '/api', но простые '/' не очень .
Если я пытаюсь обратится не к '/api', идёт просто переброс на корень сайта.

Вот сам сайт
Видео о проблеме
  • Вопрос задан
  • 149 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы