如何设置“默认页面"在Linux服务计划上的Azure Web App中使用Angular [英] How to set "default page" for Angular in Azure Web App on Linux service plan
问题描述
我可以在Linux服务计划上将Angular部署到Azure Web Apps,当点击{myapp} .azurewebsites.net/index.html
I can deploy Angular to Azure Web Apps on Linux service plan and it works fine when hitting {myapp}.azurewebsites.net/index.html
我可以按预期在应用内导航.
I can navigate inside the app as expected.
点击根目录{myapp} .azurewebsites.net时,它只会显示hostingstart.html.
When hitting the root {myapp}.azurewebsites.net it just displays the hostingstart.html.
按照某些文章中的建议删除hostingstart.html并没有帮助.
It does not help to remove the hostingstart.html as suggested in some articles.
如果我尝试直接点击子页面的网址(例如{myapp} .azurewebsites.net/mypage),则会收到错误消息:无法获取/mypage (在本地运行时有效)
If I try to hit a sub page url directly (like {myapp}.azurewebsites.net/mypage) then I get an error : Cannot GET /mypage (this works when I run locally)
我怀疑我需要设置默认页面,但是我无法在Azure Web App的应用程序设置"中的任何位置找到此页面. (我认为这仅适用于Windows服务计划,而不适用于Linux服务计划.)
I suspect that i need to setup a default page, but i cannot find this anywhere in the Application Settings in the Azure Web App. (I think this is only available on Windows service plans - not on Linux Service Plans).
我如何正确部署到Linux App Service才能正常工作?
How do i deploy properly to Linux App Service for this to work ?
我找到了很多有关此问题的文章,但它们似乎都涵盖了Windows App Service Plan.
I have found a lot of articles on the issue, but they all seem to cover Windows App Service Plan.
推荐答案
您需要向Apache服务器添加URL重写规则,以便将任何页面请求重定向到Angular的index.html
You need to add URL rewrite rules to the Apache server so that any page request gets redirected to Angular's index.html
将此粘贴到您的根.htaccess
文件中:
Paste this into your root .htaccess
file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
(来源: https://github.com/angular/angular/issues/11884#issuecomment-288852433 )
:如果使用的是node.js后端,请参见以下SO答案以供参考: https://stackoverflow.com/a/34864585/235648
If using a node.js backend, see this SO answer for reference: https://stackoverflow.com/a/34864585/235648
这篇关于如何设置“默认页面"在Linux服务计划上的Azure Web App中使用Angular的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!