antoinemartin / django-windows-tools

Django application providing management commands to host Django projects in Windows environments
BSD 2-Clause "Simplified" License
51 stars 13 forks source link

Internal Server Error - The FastCGI process exited unexpectedly #28

Open ClayMDMI opened 6 years ago

ClayMDMI commented 6 years ago

I have been getting an error with FastCGI when I try to use the django-windows-tool to configure my Django Project to run on IIS. When I run python manage.py winfcgi_install while in my virtual environment, a new web.config file, a new app pool, a new FastCGI application, and a new web site all appear as intended. I bind the website to a new port, then change the app pool Identity from "ApplicationPoolIdentity" to "LocalSystem". However, after navigating to the website I get an error.

HTTP Error 500.0 - Internal Server Error
C:\Users\Clay.MDMI\PyRO\myvenv\Scripts\python.exe - The FastCGI process exited unexpectedly

Most likely causes:
IIS received the request; however, an internal error occurred during the processing of the request. The root cause of this error depends on which module handles the request and what was happening in the worker process when this error occurred.
IIS was not able to access the web.config file for the Web site or application. This can occur if the NTFS permissions are set incorrectly.
IIS was not able to process configuration for the Web site or application.
The authenticated user does not have permission to use this DLL.
The request is mapped to a managed handler but the .NET Extensibility Feature is not installed.

Things you can try:
Ensure that the NTFS permissions for the web.config file are correct and allow access to the Web server's machine account.
Check the event logs to see if any additional information was logged.
Verify the permissions for the DLL.
Install the .NET Extensibility feature if the request is mapped to a managed handler.
Create a tracing rule to track failed requests for this HTTP status code. For more information about creating a tracing rule for failed requests, click here.

Module | FastCgiModule
Notification | ExecuteRequestHandler
Notification | FastCGI
Error Code | 0x00000001

Requested URL | http://localhost:81/
Physical Path | c:\users\clay.mdmi\pyro\proj
Logon Method | Anonymous
Logon User | Anonymous

Obviously, this error message isn't super helpful. After a suggestion on another issue here, I tried adding lines to my web.config file shown below to have it print more information, but it doesn't change the result.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.web>
    <customErrors mode="Off" />
  </system.web>
  <system.webServer>
    <httpErrors errorMode="Detailed" />
    <handlers>
      <clear/>
      <add name="FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Users\Clay.MDMI\PyRO\myvenv\Scripts\python.exe|C:\Users\Clay.MDMI\PyRO\proj\manage.py winfcgi --pythonpath=C:\Users\Clay.MDMI\PyRO\proj" resourceType="Unspecified" requireAccess="Script" />
    </handlers>
  </system.webServer>
</configuration>

I saw some people talking about needing to grant the app pool permission to the project directory, so I followed the instructions HERE (performed on the root folder, changed permissions for all folders inside as well) but nothing changed.

Any ideas on next steps? Could this be an issue with my virtual environment? I very much appreciate any help, as well as the fact that this tool just exists in the first place!

More info: Django v2.1 Anaconda v5.2 Python v3.6.3 IIS v10

mrbean-bremen commented 6 years ago

If using a virtual environment, the Scripts path of the environment most be in the system path, otherwise the webservice will not be able to execute the program. If this is already the case, you could anyway try to use the system-wide Python temporarily instead of the virtual env, just to check if the virtual environment is the problem.

mrbean-bremen commented 6 years ago

Also, I haven't tested with Django 2 yet (last tested with 1.11), though I don't really think that this is the problem.

ClayMDMI commented 6 years ago

First of all, thanks for replying so fast!

I ran it on my full installation of Python as well to the same result. Out of curiosity, why do you not think that Django 2 is the source of the problem?

mrbean-bremen commented 6 years ago

Sorry, right now I don't have another idea. About Django 2 - I don't think it is a problem, justed wanted to mention that I haven't tested it, so I can't be sure. Using Django 1.11 with Python 3.6 and IIS 10 has worked for me without problems.

ClayMDMI commented 6 years ago

Update - I tested this with a new default Django 1.11.0 project and it failed. I also tested on Python 2.7 just for thoroughness, but no dice.

Another thing I noticed, the installation guide says

the winfcgi_install command provides numerous options. To list them, type: D:\sites\mydjangoapp> python help winfcgi_install

and

Take the fcgi.py file and copy it in the management\commands directory of one of your project applications so that the manage.py help fcgi command returns you: [Picture of help options]

But both of those commands return nothing for me, they are unknown commands. Could it be a clue?

mrbean-bremen commented 6 years ago

Sorry for the late response - I didn't really have time to look into this. The python help winfcgi_install was obviously a typo , it shall read python manage.py help winfcgi_install - I corrected this in the README. As for the second one - I haven't done this (don't have a system to try this at the moment), but I see no reason why it shouldn't work. You have to call it from the web root of your application, where you have copied the file, of course - but I guess you did this. I may try this later and check if it works.

beruic commented 6 years ago

I have this same issue. My setup is the following:

Django: v1.11.15 Python: v3.6.6 IIS: v10 django-windows-tools: 0.2.1 I use a virtual environment.

Details: I have not copied the fcgi.py file, and I cannot find it in the documentation. However I noticed the following:

Futhermore, I would like to know if there is a way that I can see what exactly caused the failed request? Or perhaps run a test request from the commandline?

lewisMachilika commented 4 years ago

whoever got this right, please help. I have the same problem.

pankajan05 commented 1 month ago

I am also having the same problem.