nginx配置文件放在哪里?

Where to put nginx configuration file?

我知道我应该输入这段代码以便 HTML5 历史回退:

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

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

但是到哪个文件?尝试搜索 google,没有任何效果,将上面的代码放在 /etc/nginx/nginx.conf 中会使 nginx 无法工作。

我正在使用 vagrant Homestead laravel。

请帮忙。

这是 nginx.conf 文件的条目,位于

/etc/nginx/nginx.conf

将此添加到配置中:

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

将配置放在/etc/nginx/nginx.conf

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

最后,我让 nginx 与 html5 回退一起工作。

打开 /etc/nginx/site-available/homestead.app,或您在 homestead.yaml 文件中指定的任何域。

put/replace "location" 节

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

然后保存,然后打开laravel web.php(路由器)。输入此代码:

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

以上代码防止 laravel 返回错误 404。现在 vue html5 历史回退在没有 # 符号的情况下工作。

感谢大家的帮助,没有你们我可能不知道解决这个问题。

如果您要查找 NGINX 配置文件的位置:

  • 主要配置文件是/etc/nginx/nginx.conf
  • 此文件的默认版本将所有匹配 /etc/nginx/conf.d/*.conf 的文件加载到其 http 块中。
  • 所以如果你想指定一个 server 块,你可以覆盖 /etc/nginx/conf.d/default.conf 或在那里添加你自己的 .conf 文件。