我正在构建角度应用程序,并希望将URL路由到http://localhost/sample/AngularApp/。但不想在浏览器中提供整个URL。我将给出唯一的本地主机。在angular中,在构建dist时,我们使用命令ng build --base-href=/sample/AngularApp/
并在Nginx提到的路径/usr/share/nginx/html
中创建了文件夹结构/ sample / AngularApp。因此,当仍然访问应用程序时,我们将在浏览器中提供整个路径。因此,如何解决此问题以及如何在nginx.conf文件中配置该路径以自动路由URL?
我会使用标准配置:
server {
listen 80;
listen [::]:80;
root /var/www/html/YourAngularApp/dist;
index index.html index.htm;
location / {
try_files $uri $uri/ /index.html;
}
}
这提供了服务其他文件(如果找到)或退回到位于项目根目录的index.html的机会。