将django部署到UserDir [英] deploying django to UserDir

查看:153
本文介绍了将django部署到UserDir的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我们的学生服务器上部署我的django宠物项目。我们有apache2与UserDir mod,我没有访问apache2配置文件。如何部署? :-D



我来自PHP背景,我通过将其上传到我的 public_html 目录中来部署我的PHP脚本所有内容都会显示在 http://ourserver.com/~myusername 上。我读了django文档,它说我应该在我们的apache配置文件中添加< Location>一些东西< / Location> 。我无法访问它,所以我尝试将它放在.taccess中的 public_html 目录中,并没有起作用。我google了很多,我觉得我读了你不能在.htaccess中的< Location> 的地方,但现在我找不到那个报价。



所以,任何人在这里部署django到UserDir,而不会骚扰apache管理员?



编辑:
我测试了mod_python,因为Graham Dumpleton建议这里,我可以使用mod_python没有问题。另外,我发现错误日志,这里是什么错误日志说,当我把。code>< Location>一些东西< / Location> 在.htaccess中:



[Thu Oct 01 21:33:19 2009] [alert] [client 188.129.74.66] /path/to/my/.htaccess:<位置不允许这里



所以,好像我真的不能把< Location> into .htaccess。那么,我的选择是什么?

解决方案

如果安装了mod_python,首先看看你是否可以使用它,而不需要管理员做任何事情。阅读:



http ://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking



除非您是受信任的用户或管理员不知道什么他们正在做,他们不应该允许你使用mod_python,因为你的代码将作为Apache用户运行,如果任何人也以同样的方式运行应用程序,你可能会干扰彼此的应用程序和数据。换句话说,它不是安全的,不应该在同一Apache实例上的多个用户的共享托管环境中使用。






更新1



在您现在拥有mod_python的基础上,您应该可以用以下代码替换mptest.py的内容:

  import os 
os.environ ['DJANGO_SETTINGS_MODULE'] ='mysite.settings'

import sys
sys.path.insert(0,'/ some / path / to / project / area / mysite')
sys.path.insert(0,'/ some / path / to / project / area')

从django.core.handlers.modpython导入处理程序作为_handler

def处理程序(req):
req.get_options()['django.root'] ='/~myusername/mptest.py'
return _handler(req)

显然,各种路径和值应根据您的命名进行更改。



该网站将被访问为/~myusername/mptest.py。



此时你会发现愚蠢使用mod_python是你没有Apache的控制。这是因为当您更改网站中的代码时,您需要请管理员为您重新启动Apache,以便您的更改被选中。



在其中使用mod_wsgi守护进程模式与你作为守护进程的所有者将会更好,但是如果他们已经在运行mod_python,我不会建议他们同时加载两个模块,因为mod_python问题在某些情况下会使用mod_wsgi,如果他们避开' t正确安装Python,你可能会遇到很多问题,所以不值得的麻烦。



简而言之,在没有控制权的共享托管环境中使用mod_python的Apache是​​愚蠢和不安全的。



所有这一切都记录了如何从每个用户目录中运行Django,因为我以前没有记录它。


I would like to deploy my django pet-project on our student server. We have apache2 with UserDir mod and I don't have access to apache2 config files. How do I deploy? :-D

I come from PHP background and I deploy my PHP scripts by uploading them to my public_html dir and everything shows up on http://ourserver.com/~myusername. I read django documentation and it says I should add <Location>some stuff</Location> to our apache config file. I don't have access to it, so I tried putting it in .htaccess in my public_html dir and that didn't work. I googled a lot and I think I read somewhere you can't put <Location> in .htaccess, but now I can't find that quote.

So, anybody here deployed django to UserDir without harassing apache admins?

edit: I tested mod_python as Graham Dumpleton advised here, and I can use mod_python without problems. Also, I found error log and here is what error log says when I put <Location>some stuff</Location> in .htaccess:

"[Thu Oct 01 21:33:19 2009] [alert] [client 188.129.74.66] /path/to/my/.htaccess: <Location not allowed here"

So, it seems like I really can't put <Location> into .htaccess. So, what are my options?

解决方案

If mod_python installed, first see if you can actually use it without needing administrator to do anything. Read:

http://www.dscpl.com.au/wiki/ModPython/Articles/GettingModPythonWorking

Unless you are a trusted user or administrators don't know what they are doing, they shouldn't be allowing you to use mod_python because your code will run as Apache user and if anyone else also running applications same way, you could interfere with each others applications and data. In other words it isn't secure and shouldn't be used in shared hosting environments where multiple users on same Apache instance.


UPDATE 1

On the basis that you now have mod_python working, you should be able to replace contents of mptest.py with something like:

import os
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'

import sys
sys.path.insert(0, '/some/path/to/project/area/mysite')
sys.path.insert(0, '/some/path/to/project/area')

from django.core.handlers.modpython import handler as _handler

def handler(req):
  req.get_options()['django.root'] = '/~myusername/mptest.py'
  return _handler(req)

Obviously, various paths and values in that should be changed per your naming.

The site would be accessed as '/~myusername/mptest.py'.

At this point you will find out silly using mod_python is where you don't have control of Apache. This is because when you change code in your site, you will need to ask the administrators to restart Apache for you for your changes to be picked up.

Using mod_wsgi in its daemon mode with you as owner of daemon process would be much better, but if they are already running mod_python I wouldn't be recommending they load both modules at same time as mod_python issues screw up use of mod_wsgi in some cases and if they haven't installed Python properly, you are just likely to have lots of issues and so not worth the trouble.

In short, using mod_python in shared hosting environment where you have no control of Apache is silly and insecure.

All the same, have documented how to run Django out of per user directory as I don't think it has been documented anywhere previously.

这篇关于将django部署到UserDir的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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