X
X
XtReLL2019-03-05 14:25:29
Nginx
XtReLL, 2019-03-05 14:25:29

Routing Laravel + AngularJS Nginx. How to set up requests?

Hello. There is a web server with Nginx web handler. Backend - laravel, Front - AngularJS.
Laravel routes are arranged like this. Communicating with AngularJS via "/api", With simple requests "/'
Here is the file itself

Routuses
<?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', '[email protected]');
    Route::get('/auth/handle', '[email protected]');
    Route::get('/auth/logout', '[email protected]');
  Route::post('/payapi/pushback', '[email protected]');
  Route::post('/sci/checkout', '[email protected]');
    Route::post('/getUser', '[email protected]');
    Route::post('/getCases', '[email protected]');
    Route::post('/getCase', '[email protected]');
    Route::post('/openCase', '[email protected]');
    Route::post('/updateBalance', '[email protected]');
    Route::post('/getLiveDrop', '[email protected]');
    Route::post('/getStatistic', 'CasesCo[email protected]');
    Route::post('/sell', '[email protected]');
    Route::post('/profile', '[email protected]');
    Route::post('/saveTradeLink', '[email protected]');
    Route::post('/getTop', '[email protected]');
    Route::post('/getProfilePartner', '[email protected]');
    Route::post('/getInvite', '[email protected]');
    Route::post('/getMyCode', '[email protected]');
    Route::post('/withdrawItem', '[email protected]');
    Route::post('/withdrawStatus', '[email protected]');
    Route::post('/setOfferID', '[email protected]');
    Route::post('/withdrawStatusOffer', '[email protected]');
    Route::post('/pushNewItems', '[email protected]');
    Route::post('/payment/sumPayment', '[email protected]');
    Route::post('/payment/sumSkins', '[email protected]');
    Route::post('/checkStatus', '[email protected]');
    Route::post('/checkBuyItems', '[email protected]');
  Route::post('/getTrades', '[email protected]');
  Route::post('/promoItem', '[email protected]');
  
Route::group(['middleware' => 'access'], function () {
        Route::get('/admin/stats', '[email protected]');
        Route::get('/admin/stats/case', '[email protected]');
        Route::get('/admin/stats/users', '[email protected]');
        Route::get('/admin/items', ['as' => 'items', 'uses' => '[email protected]']);
        Route::get('/admin/items/delete/{id}', ['as' => 'items', 'uses' => '[email protected]']);
        Route::get('/admin/itemsban', ['as' => 'itemsban', 'uses' => '[email protected]']);
        Route::get('/admin/search', ['as' => 'search', 'uses' => '[email protected]']);
        Route::get('/admin/searchusers', ['as' => 'search', 'uses' => '[email protected]']);
        Route::get('/admin/users', ['as' => 'users', 'uses' => '[email protected]']);
        Route::get('/admin/user/{id}', ['as' => 'users', 'uses' => '[email protected]']);
        Route::get('/admin/lastmoney/{id}', ['as' => 'lastmoney', 'uses' => '[email protected]']);
        Route::match(['get', 'post'], '/admin/givemoney/{id}', ['as' => 'givemoney', 'uses' => '[email protected]']);
        Route::match(['get', 'post'], '/admin/edit/{id}', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::match(['get', 'post'], '/admin/userdit', ['as' => 'user', 'uses' => '[email protected]']);
        Route::get('/admin/items/cat/{id}', ['as' => 'items', 'uses' => '[email protected]']);
        Route::get('/admin/case/{id}', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/admin/items/{id}', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/admin/itemsnew', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/admin/cases', ['as' => 'cases', 'uses' => '[email protected]']);

        /*Prizes*/
        Route::get('/admin/prize', '[email protected]');
        Route::get('/admin/prize/add', '[email protected]');
        Route::get('/admin/prize/edit/{id}', '[email protected]');
        Route::get('/admin/prize/delete/{id}', '[email protected]');

        Route::match(['get', 'post'], '/admin/prize/new', '[email protected]');
        /*Prizes*/

        /*GROUPS*/
        Route::get('/admin/groups', 'Admin\[email protected]');
        Route::get('/admin/groups/add', 'Admin\[email protected]');
        Route::get('/admin/groups/edit/{id}', 'Admin\[email protected]');
        Route::get('/admin/groups/delete/{id}', 'Admin\[email protected]');

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

        Route::match(['get', 'post'],'/admin/casesedit', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::match(['get', 'post'],'/admin/itemsedit', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::match(['get', 'post'],'/admin/config', ['as' => 'config', 'uses' => '[email protected]']);
        Route::match(['get', 'post'],'/admin/clearstats', '[email protected]');
        Route::match(['get', 'post'],'/admin/deletegames', '[email protected]');
        Route::get('/admin322', ['as' => 'admin', 'uses' => '[email protected]']);
        Route::get('/admin/case', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/admin/log', ['as' => 'log', 'uses' => '[email protected]']);
        Route::get('/admin/game', ['as' => 'game', 'uses' => '[email protected]']);
        Route::get('/admin/inventory', '[email protected]');
        Route::get('/admin/config', ['as' => 'config', 'uses' => '[email protected]']);
        Route::get('/listbuy', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/listupdate', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/admin/transactions', '[email protected]');
        Route::get('/admin/skinpay', '[email protected]');
        Route::get('/admin/useritems', '[email protected]');
        Route::get('/admin/listbuy', ['as' => 'cases', 'uses' => '[email protected]']);
        Route::get('/admin/delay', '[email protected]');
        Route::match(['get', 'post'],'/admin/nullitem', '[email protected]');
        /********** TABLE ROUTES *********/

        Route::get('/admin/table/stat', 'Admin\[email protected]');
        Route::get('/admin/table/our', 'Admin\[email protected]');
        Route::get('/admin/table/advert', 'Admin\[email protected]');
        Route::get('/admin/table/calendar', 'Admin\[email protected]');

        Route::get('/admin/table/stat/add', 'Admin\[email protected]');
        Route::get('/admin/table/our/add', 'Admin\[email protected]');
        Route::get('/admin/table/advert/add', 'Admin\[email protected]');

        Route::match(['get', 'post'],'/admin/table/stat', 'Admin\[email protected]');
        Route::match(['get', 'post'],'/admin/table/our', 'Admin\[email protected]');
        Route::match(['get', 'post'],'/admin/table/advert', 'Admin\[email protected]');

        Route::match(['get', 'post'],'/admin/table/stat/del', 'Admin\[email protected]');
        Route::match(['get', 'post'],'/admin/table/our/del', 'Admin\[email protected]');
        Route::match(['get', 'post'],'/admin/table/advert/del', 'Admin\[email protected]');
        Route::get('/admin/table/advert/change/{id}', 'Admin\[email protected]');
        Route::match(['get', 'post'],'/admin/table/advert/change', 'Admin\[email protected]');
        //Route::get('/newdemo', ['as' => 'newgdemo', 'uses' => '[email protected]']);
        // Route::get('/newgame', ['as' => 'newgame', 'uses' => 'Games[email protected]']);

        Route::get('/admin/codes', '[email protected]');
        Route::get('/admin/codes/add', '[email protected]');
        Route::post('/admin/codes/add', '[email protected]');
        Route::get('/admin/codes/delete/{id}', '[email protected]');
    });

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


And here is the Nginx config
nginx config
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;
}


}


But the problem is that my config seems to handle requests with '/api' just fine, but simple '/' doesn't.
If I try to access something other than '/api', it just redirects to the root of the site.
Here is the site
Video about the problem

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question