Search code examples
laravelnginxvagrantvuejs2html5-history

Where to put nginx configuration file?


I understand that i should put this code in order to make HTML5 History fallback:

location / {
  try_files $uri $uri/ /index.html;
}

https://router.vuejs.org/en/essentials/history-mode.html

but to which file? tried search google, nothing works, put above code in /etc/nginx/nginx.conf will make nginx not working.

im using vagrant Homestead for laravel.

please help.


Solution

  • Finally, i get nginx work with html5 fallback.

    open /etc/nginx/site-available/homestead.app, or any domain your specified in your homestead.yaml file.

    put/replace "location" section with

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

    then save, and open laravel web.php (router). put this code:

    Route::get('/{vue?}/{vue2?}/{vue3?}', function () {
    //    return view('welcome');
        if ( ! request()->ajax() ) {
            return view('index');
        }
    });
    

    above code prevent laravel to returning error 404. now vue html5 history fallback works without # sign.

    thanks everyone for trying to help, without you guys i may not have any idea to resolve this issue.