如何在Azure上部署Django应用程序?

问题描述:

我之前发布过,但没有收到答案. 我有一个在VS2017中开发的Django Web应用程序.我已经发布了,但是出现服务器错误.您能告诉我我需要如何配置我的web.config文件以使其起作用吗?当前是:

I have posted before but not received an answer. I have a Django web app developed in VS2017. I have published it but getting a server error. Can you please advise how I need to configure my web.config file so that it works? Currently it's:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_HANDLER" value="app.wsgi_app"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\Python361x64\python.exe|D:\home\Python361x64\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
  </system.webServer>
</configuration>

但是我收到服务器错误,Python日志文件显示:

but I am getting an server error and Python log file says:

D:\ home \ Python361x64 \ python.exe:无法打开文件'D:\ home \ site \ wwwroot \ runserver.py':[错误2]没有这样的文件或目录

D:\home\Python361x64\python.exe: can't open file 'D:\home\site\wwwroot\runserver.py': [Errno 2] No such file or directory

我将不胜感激.

您需要将static files url configuration添加到KUDU上的web.config文件中,其中提到

You need to add static files url configuration to web.config file on KUDU which mentioned here.

我已经尝试将自己的Django项目部署到azure并使用您的web.config文件,并且效果很好.

I've tried to deploy my own Django project to azure and use your web.config file,and it works well.

您可以参考以下web.config配置:

<configuration>
  <appSettings>
    <add key="WSGI_HANDLER" value="DjangoWebProject1.wsgi.application"/>
    <add key="PYTHONPATH" value="D:\home\site\wwwroot"/>
    <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
  </appSettings>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python362x86\python.exe|D:\home\python362x86\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="Static Files" stopProcessing="true">
          <conditions>
            <add input="true" pattern="false" />
          </conditions>
        </rule>
        <rule name="Configure Python" stopProcessing="true">
          <match url="(.*)" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_URI}" pattern="^/static/.*" ignoreCase="true" negate="true" />
          </conditions>
          <action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>

注意 :

Note:

请确保

<add name="PythonHandler" path="handler.fcgi" verb="*" modules="FastCgiModule" scriptProcessor="D:\home\python362x86\python.exe|D:\home\python362x86\wfastcgi.py" resourceType="Unspecified" requireAccess="Script"/>

<action type="Rewrite" url="handler.fcgi/{R:1}" appendQueryString="true" />