在与根文件夹不同的文件夹中部署Angular应用 [英] Deploying Angular app in a different folder than root folder

查看:64
本文介绍了在与根文件夹不同的文件夹中部署Angular应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angular的新手.如果部署在 nginx /var/www/mydomain.com/html 中,则应用程序可以正常运行.但我想将其部署在/var/www/mydomain.com/html/myapp 文件夹中.我将 nginx可用站点设置到此文件夹,并且 index.html 正常工作.但是试图从/var/www/mydomain.com/html/images 文件夹(因此404错误代码)而不是/var/www/mydomain.com/html/myapp/images 文件夹.如何在Angular中全局设置URL前缀/myapp ,以便所有相对路径都具有此前缀.我在这里看到了一些答案,但它们需要更改组件代码.没有办法在部署时进行此设置,以便可以在任何路径中部署相同的 dist 吗?

New to Angular. App works fine if deployed in nginx /var/www/mydomain.com/html. But I want to deploy it in /var/www/mydomain.com/html/myapp folder. I setup nginx available sites to this folder and index.html works fine. But relative paths in Angular app (e.g., images/mypic.png) being attempted to be retrieved from /var/www/mydomain.com/html/images folder (hence 404 error code) instead of /var/www/mydomain.com/html/myapp/images folder. How do I set a url prefix /myapp globally in Angular so all relative paths have this prefix. I have seen some answers here but they require changes in the component code. Isn't there a way to made this setting at deployment time so the same dist can be deployed in any path?

推荐答案

使用以下命令,此处/myapp/是根站点的相对路径.

Use the following command, here /myapp/ is the relative path to the root site.

ng build --prod --base-href /myapp/

这篇关于在与根文件夹不同的文件夹中部署Angular应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆