带有fastcgi的Django 2.0.7在浏览器中提供404,但可在命令行上使用 [英] Django 2.0.7 with fastcgi gives 404 in browser but works on command line

查看:94
本文介绍了带有fastcgi的Django 2.0.7在浏览器中提供404,但可在命令行上使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在bluehost共享服务器上建立一个小型django项目,但在我认为应该是最后一步的问题上却遇到了麻烦-使它与fastcgi一起运行.

I'm trying to set up a small django project on a bluehost shared server and am having trouble on what I think should be the last step - getting it running with fastcgi.

我使用miniconda安装了python 3.7.0和django 2.0.7,并能够创建一个项目/应用程序,但是我无法在浏览器中显示它(FWIW,我已经在另一个Bluehost网站上成功完成了此操作一项类似的计划,尽管该网站属于共享加号"计划,而该网站只是基本计划,但我不知道这是否是问题所在

I installed python 3.7.0 and django 2.0.7 using miniconda and was able to create a project/app but i can't get it to display in a browser (FWIW, I have successfully done this with another bluehost site on a similar plan, though that site is under the "shared plus" plan while this one is just the basic, but I don't know if that's the issue)

在我的〜/public_html/myproject/.htaccess文件中:

In my ~/public_html/myproject/.htaccess file I have:

AddHandler fastcgi-script .fcgi
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /home/username/public_html/myproject/myproject.fcgi/$1 [QSA,L]

在myproject.fcgi中,我有:

And in myproject.fcgi I have:

#!/home/username/miniconda3/bin/python
# -*- coding: utf-8 -*-
import sys, os
project_name = "myproject"

sys.stdout=open('/home/username/public_html/myproject/test.out','w')
print(project_name)

# Add a custom Python path.
sys.path.insert(0, "/home/username/miniconda3/bin/python")
sys.path.insert(0, "/home/username/public_html/myproject")
sys.path.insert(0, os.getcwd() + "/" + project_name)

os.environ['DJANGO_SETTINGS_MODULE'] = project_name + '.settings'

from django_fastcgi.servers.fastcgi import runfastcgi
from django.core.servers.basehttp import get_internal_wsgi_application

wsgi_application = get_internal_wsgi_application()
runfastcgi(wsgi_application, method="prefork", daemonize="false", minspare=1, maxspare=1, maxchildren=1)

此配置在另一个站点上对我有用,但是在这里,我只能在命令行上成功运行./myproject.fcgi,但是在浏览器中却看到404.

This configuration worked for me on the other site, but here I am only able to run ./myproject.fcgi successfully on the command line, but I get a 404 in the browser.

我无法访问服务器日志,因此我在fcgi脚本中添加了一行以将stdout定向到文件,并发现未生成该文件,因此我不确定访问python安装是否有问题当我尝试在浏览器中加载页面时,还是什么(我对此很陌生!)

I'm unable to access my server logs so I added a line to the fcgi script to direct stdout to a file and find that the file is not produced, so I'm not sure if something's wrong with accessing my python install when I try to load the page in the browser, or what (I'm pretty new to this!)

我实际上在这里找到了我的确切问题,很遗憾没有答案: 使用FastCGI的Django在浏览器中提供404,但在命令行上工作

I found practically my exact question here, unfortunately without an answer: Django with FastCGI gives 404 in browser but works on command line

谢谢!

推荐答案

更新:我最终确定我面临的问题是由于共享托管环境的限制.对于初学者来说,如果没有root访问权限或对apache错误日志的访问,安装和故障排除将很困难,但是我能够进行安装,并且当我意识到bluehost计划需要从cgi-bin目录运行cgi脚本时,我取得了额外的进步. (而不是像大多数教程所建议的那样在.htaccess中添加处理程序).

Update: I ended up determining that the issue I was facing was due to the limitations of my shared hosting environment. For starters, installation and troubleshooting was difficult without root access or access to apache error logs, but I was able to get an installation working, and made additional progress when I realized that my bluehost plan required cgi scripts to run from the cgi-bin dir (rather than adding handlers in .htaccess as most tutorials suggested).

但是,我无法克服的最后一个障碍似乎是对产生的线程数的限制-当我尝试在浏览器中加载站点(django测试页)时,它会挂起并且我会得到一个我的shell会话中出现错误:-jailshell: fork: Resource temporarily unavailable,如此处. ……可能有更多经验的人可以解决这个问题,但我最终决定切换起来会更容易.由于我已经成功地在另一个bluehost共享服务器帐户上完成了完全相同的事情,所以我花了比原本应该花费的时间更长的时间,但是我终于了解到bluehost更新了他们的计划,而另一个则仅在旧版本上才起作用计划的版本.

However, the final hurdle I couldn't overcome seemed to be a limit on the number of spawned threads - when I tried to load the site (django test page) in the browser, it would just hang and I would get an error in my shell session: -jailshell: fork: Resource temporarily unavailable, as described here. … it's possible that someone with more experience could have figured it out but I finally decided it would be easier to switch. It took me longer to give up than it should have, since I have successfully done the exact same thing on another bluehost shared server account, but I finally learned that bluehost has updated their plans and the other one only worked since it was on an older version of the plan.

我切换到dreamhost(及其共享的服务器计划),并且能够轻松地运行所有内容!

I switched to dreamhost (with their shared server plan) and was able to get everything running easily!

这篇关于带有fastcgi的Django 2.0.7在浏览器中提供404,但可在命令行上使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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