在Azure应用服务中添加重写规则的正确方法是什么 [英] What is the proper way to add rewrite rules in an Azure App Service

查看:52
本文介绍了在Azure应用服务中添加重写规则的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想向我的Azure应用服务中添加重写规则,但是,即使我尝试通过如下所示的简单重写来创建web.config,该站点也会返回HTTP 500.

 <?xml version ="1.0" encoding ="UTF-8"?><配置>< system.webServer>< rewrite><规则><规则名称="Test" stopProcessing ="true">< match url ="test"/>< action type ="Rewrite" url ="/index.html"/></rule></rules></rewrite></system.webServer></configuration> 

我要做的是从头开始创建web.config并将其通过FTP传输到应用程序服务的wwwroot文件夹中,在该文件夹中,我保留了其余的网站文件.

我已经看到此其他链接似乎表明可以更新web.config,但是他们的示例也为我提供了HTTP 500.

我已经浏览了Azure门户中的应用程序服务的配置选项,但似乎没有什么事情可以吸引我的.

解决方案

>>"此其他链接似乎表明可以更新web.config."

是的,我们可以通过直接更新Web.config文件来更新Web App的配置.您可以通过FTP/WebDeply或Kudu提供的任何其他方式将配置文件的新版本上传到wwwroot文件夹.编辑wwwroot文件夹中文件的另一种简便方法是使用

  • 创建2个文件,一个index.html文件和一个Web.config文件.Web.config中的内容与您的内容相同.
  • 使用FTP将这些文件上传到我的Web应用程序的wwwroot文件夹中.
  • 打开网络浏览器,然后输入类似"http://xxx.azurewebsites.net/test"的URL.Web服务器将返回index.html的内容.证明重写工作正常.
  • >>但他们的示例也为我生成了HTTP 500."

    首先,请标记重写是否正常.建议您直接查看index.html页面,并检查错误代码(500)是否来自index.html页面.

    有时我们为重写规则提供了错误的语法,它将返回500(URL重写模块错误).您是否为Web应用程序启用了详细错误日志记录"和"Web服务器日志记录".如果是,则可以查看详细错误消息以获取更多有用的信息.有关如何启用和查看诊断日志记录的信息,下面的链接供您参考.

    启用诊断日志记录适用于Azure App Service中的Web应用程序

    I want to add re-write rules to my Azure app service, but if I even try create a web.config with a simple rewrite as shown below, the site returns an HTTP 500.

    <?xml version="1.0" encoding="UTF-8"?>
    
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Test" stopProcessing="true">
                        <match url="test" />
                        <action type="Rewrite" url="/index.html" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    What I did is create the web.config from scratch and FTP it into the wwwroot folder for the app service which is where I Ftp'd the rest of my web site files.

    I have seen an old conversation about web.config files in Azure, but I'm not even sure if this is in regards to Azure app service - and things change so quickly in Azure that I thought I should ask separately anyways.

    I have also seen this link about using web.config transforms. Maybe this is required?

    This other link seems to indicate that updating web.config is possible, but their example results in an HTTP 500 for me as well.

    I've looked through configuration options in the Azure portal for my app service and nothing seems to jump out at me.

    解决方案

    >>"This other link seems to indicate that updating web.config is possible"

    Yes, we could update the configuration of Web App by updating Web.config file directly. You could upload a new version of configuration file to wwwroot folder by FTP/WebDeply or any other ways provided by Kudu. Another easy way to edit files in wwwroot folder is using the App Service Editor, you could use it to edit the configuration file.

    I can’t reproduce your problem on my side. Following are what I done.

    1. Create a Web App using a Web App Plan with "Shared" SKU.
    2. Create 2 file, a index.html file and a Web.config file. The content in Web.config is same as yours.
    3. Upload these files to wwwroot folder of my web app using FTP.
    4. Open a web browser and input a URL like this "http: // xxx.azurewebsites.net/test". The web server will return the content of index.html. It proves that the rewrite is working fine.

    >>"but their example results in an HTTP 500 for me as well."

    Firstly, please mark sure whether the rewrite is working fine or not. I suggest you view the index.html page directly and check whether the error code(500) comes from index.html page.

    Sometimes we provide the wrong syntax for rewrite rule, it will return 500 (URL Rewrite Module Error). Have you enabled Detailed Error Logging and Web Server Logging for your web app. If yes, you could view the detail error message to get more useful information. For how to enable and view diagnostics logging, link below is for your reference.

    Enable diagnostics logging for web apps in Azure App Service

    这篇关于在Azure应用服务中添加重写规则的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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