Django 部署 - 在 fastCGI 应用程序配置中找不到 scriptProcessor

问题描述 投票:0回答:1

我正在学习通过 IIS 和 fastCGI 部署 Django 项目的过程。但是,我遇到了错误

<handler> scriptProcessor could not be found in <fastCGI> application configuration

经过一些研究,我发现这个错误可能是由于配股造成的。因此,我在文件夹 Python37(包含 python 虚拟环境)中为用户

DefaultAppPool
添加了权限(读取、写入、执行),类似地,我也为位于
C:\inetpub
上的文件夹 wwwroot 执行了此操作。

Python 虚拟环境:

C:\python37
Web.config 文件路径:
C:\inetpub\wwwroot\web.config

Web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="Python FastCGI" 
      path="*" 
      verb="*" 
      modules="FastCgiModule" 
      scriptProcessor="c:\python37\scripts\python.exe|c:\python37\lib\site-packages\wfastcgi.py>" 
      resourceType="Unspecified" 
      requireAccess="Script" />
    </handlers>
  </system.webServer>

  <appSettings>
    <add key="PYTHONPATH" value="c:\python37\scripts\python.exe" />
    <add key="WSGI_HANDLER" value="manhour_site.wsgi.application" />
    <add key="DJANGO_SETTINGS_MODULE" value="manhour_site.settings" />
  </appSettings>
</configuration>

进行上述更改后,我仍然面临类似的问题,因此我查看了这个解决方案。 根据解决方案,fastCGI 设置必须位于

applicationHost.config
文件中。该文件位于路径
C:\Windows\System32\inetsrv\config\applicationHost.config

遵循此解决方案后,我进行了以下更改

applicationHost.config

<system.webServer>
下我添加了以下内容

       <fastCgi>
            <application fullPath="c:\python37\scripts\python.exe" arguments="c:\python37\lib\site-packages\wfastcgi.py" maxInstances="4" signalBeforeTerminateSeconds="30">
                <environmentVariables>
                    <environmentVariable name="DJANGO_SETTINGS_MODULE" value="manhour_site.settings" />
                    <environmentVariable name="PYTHONPATH" value="c:\python37\scripts\python.exe" />
                    <environmentVariable name="WSGI_HANDLER" value="manhour_site.wsgi.application" />
                </environmentVariables>
            </application>
       </fastCgi>

我已以管理员身份运行该命令

wfastcgi-enable

我需要一个可以指出错误并帮助解决此错误的解决方案。

PS:在我的settings.py 文件中,我更改了以下内容

DEBUG = 'False'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

编辑 我已将

HttpPlatformHandler
添加到
web.config

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="fastCGI" 
      path="*" 
      verb="*" 
      modules="FastCgiModule" 
      scriptProcessor="c:\python37\scripts\python.exe|c:\python37\lib\site-packages\wfastcgi.py" 
      resourceType="Unspecified" 
      requireAccess="Script" />
    </handlers>

     <httpPlatform processPath="c:\python37\scripts\python.exe"
                  arguments="C:\inetpub\wwwroot\manhour_site\manage.py --port %HTTP_PLATFORM_PORT%"
                  stdoutLogEnabled="true"
                  stdoutLogFile="c:\home\LogFiles\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="SERVER_PORT" value="80" />
      </environmentVariables>

  </system.webServer>

  <appSettings>
    <add key="PYTHONPATH" value="c:\python37\scripts\python.exe" />
    <add key="WSGI_HANDLER" value="django.core.wsgi.get_wsgi_application()" />
    <add key="DJANGO_SETTINGS_MODULE" value="manhour_site.settings" />
  </appSettings>
</configuration>

上述更改会导致错误

The requested page cannot be accessed because the related configuration data for the page is invalid.

配置文件

\\?\C:\inetpub\wwwroot\web.config

python django iis web-deployment
1个回答
0
投票

为了解决我遇到的问题,我从 applicationHost.config 文件中复制了 fullPath 和参数值,特别是在 fastCgi 标记中,然后将它们粘贴到我的应用程序的 web.config 文件中。此外,我确保更新

<section name="handlers" overrideModeDefault="Allow" /> 

applicationHost.config 文件中的行。

© www.soinside.com 2019 - 2024. All rights reserved.