tonywei
tonywei

Reputation: 725

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.

Upvotes: 5

Views: 7964

Answers (4)

TheHowlingHoaschd
TheHowlingHoaschd

Reputation: 696

If you were looking for the location of the NGINX config file:

  • The main config file is /etc/nginx/nginx.conf.
  • The default version of this file loads all files matching /etc/nginx/conf.d/*.conf into its http block.
  • So if you want to specify a server block, you can overwrite /etc/nginx/conf.d/default.conf or add your own .conf file there.

Upvotes: 3

tonywei
tonywei

Reputation: 725

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.

Upvotes: 0

user320487
user320487

Reputation:

That is an entry for the nginx.conf file, located at

/etc/nginx/nginx.conf

Add this to config:

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

Upvotes: -1

Ganesh
Ganesh

Reputation: 3428

Put configuration in /etc/nginx/nginx.conf

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

Upvotes: 2

Related Questions