使用wsgi和virtualenv在没有root权限的共享web托管服务器上部署Django项目

时间:2021-02-05 20:23:01

I have a Django project which I would like to run on my shared webspace (1und1 Webspace) running on linux. I don't have root access and therefore can not edit apache's httpd.conf or install software system wide.

我有一个Django项目,我想在linux上运行我的共享webspace (1und1 webspace)。我没有root权限,因此不能编辑apache的httpd。安装或安装软件系统。

What I did so far:

到目前为止我所做的:

  • installed squlite locally since it is not available on the server
  • 本地安装squlite,因为服务器上不可用
  • installed Python 3.5.1 in ~/.localpython
  • 在~/.localpython中安装了Python 3.5.1。
  • installed virtualenv for my local python
  • 为我的本地python安装了virtualenv
  • created a virtual environment in ~/ve_tc_lb
  • 在~/ve_tc_lb中创建一个虚拟环境
  • installed Django and Pillow in my virtual environment
  • 在我的虚拟环境中安装Django和Pillow
  • cloned my django project from git server
  • 从git服务器克隆我的django项目。

After these steps, I'm able to run python manage.py runserver in my project directory and it seems to be running (I can access the login screen using lynx on my local machine).

完成这些步骤之后,我就可以运行python管理了。项目目录中的py runserver似乎正在运行(我可以在本地机器上使用lynx访问登录屏幕)。

I read many postings on how to configure fastCGI environments, but since I'm using Django 1.9.1, I'm depening on wsgi. I saw a lot about configuring django for wsgi and virtualenv, but all examples required access to httpd.conf.

我阅读了许多关于如何配置fastCGI环境的帖子,但由于我使用的是Django 1.9.1,所以我依赖于wsgi。我看到了很多关于为wsgi和virtualenv配置django的内容,但是所有示例都要求访问httpd.conf。

The shared web server is apache. I can create a new directory in my home with a sample hello.py and it is working when I enter the url, but it is (of course) using the python provided by the server and not my local installation. When I change the first line indicating which python version to use to my virtual environment (#!/path/to/home/ve_tc_lb/bin/python), it seems to use the correct version in the virtual environment. Since I'm using different systems for developing and deployment, I'm not sure whether it is a good idea to e.g. add such a line in my djangoproject/wsgi.py.

共享的web服务器是apache。我可以在我的家里创建一个新的目录和一个示例hello。py和它在我输入url时工作,但它(当然)使用的是服务器提供的python,而不是本地安装。当我更改第一行,指示将哪个python版本用于我的虚拟环境(#!/path/to/home/ve_tc_lb/bin/python)时,它似乎在虚拟环境中使用了正确的版本。由于我使用不同的系统进行开发和部署,所以我不确定在djangoproject/wsgi.py中添加这样一行是否是个好主意。

Update 2016-06-02 A few more things I tried:

更新2016-06-02我还尝试了一些东西:

  • I learned that I don't have access to the apache error logs
  • 我了解到我无法访问apache错误日志
  • read a lot about mod_wsgi and django in various sources which I just want to share here in case someone needs them in the future:
  • 阅读很多关于mod_wsgi和django的资料,我只想在这里分享,以防将来有人需要它们:modgi - IntegrationWithDjango。wiki调试mod_wsgi安装(仅适用于根用户)mod_wsgi配置指南
  • I followed the wsgi test script installation here - but the wsgi-file is just displayed in my browser instead of beeing executed.
  • 我在这里遵循了wsgi测试脚本的安装—但是wsgi文件只是在我的浏览器中显示,而不是在运行。

All in all it seems like my provider 1und1 did not install wsgi extensions (even though the support told me a week ago it would be installed)

似乎我的提供商1und1没有安装wsgi扩展(即使在一个星期前,支持告诉我它将被安装)

Update 2016-06-12: I got a reply from support (after a week or so :-S ) confirming that they dont have mod_wsgi but wsgiref...

更新2016-06-12:我得到了支持的回复(大约一周后:-S),确认他们没有mod_wsgi,而是wsgiref…

So I'm a bit stuck here - which steps should I do next? I'll update the question regularly based on comments and remarks. Any help is appreciated.

所以我被困在这里了-下一步我应该做什么?我将根据评论和评论定期更新问题。任何帮助都是感激。

2 个解决方案

#1


1  

Since your apache is shared, I don't expect you can change the httpd.conf but use instead your solution. My suggestion is:

由于您的apache是共享的,所以我不期望您可以更改httpd。同意,但用你的解决方案。我的建议是:

  1. If you have multiple servers you will deploy your project (e.g. testing, staging, production), then do the following steps for each deploy target.
  2. 如果您有多个服务器,您将部署您的项目(例如,测试、登台、生产),那么为每个部署目标执行以下步骤。
  3. In each server, create a true wsgi.py file which you will never put in versioning systems. Pretty much like you would do with a local_settings.py file. This file will be named wsgy.py since most likely you cannot edit the apache settings (since it is shared) and that name will be expected for your wsgi file.
  4. 在每个服务器中,创建一个真正的wsgi。py文件,在版本控制系统中永远不会出现。就像使用local_settings一样。py文件。这个文件将被命名为wsgy。由于大多数情况下您无法编辑apache设置(因为它是共享的),因此您的wsgi文件将需要这个名称。
  5. The content for the file will be:

    该文件的内容为:

     #!/path/to/your/virtualenv/python
     from my_true_wsgi import *
    

    Which will be different for each deploy server, but the difference will be, most likely, in the shebang line to locate the proper python interpreter.

    对于每个部署服务器,这是不同的,但是差异很可能出现在shebang行中,以定位合适的python解释器。

  6. You will have a file named my_true_wsgi to have it matching the import in the former code. That file will be in the versioning systems, unlike the wsgi.py file. The contents of such file is the usual contents of the wsgi.py on any regular django project, just that you are not using that name directly.
  7. 您将有一个名为my_true_wsgi的文件,它将匹配前一段代码中的导入。与wsgi不同,该文件将在版本控制系统中。py文件。此类文件的内容是wsgi的常见内容。对于任何常规的django项目,您都没有直接使用这个名称。

With this solution you can have several different wsgi files with no conflict on shebangs.

有了这个解决方案,您可以有几个不同的wsgi文件,而没有冲突的shebangs。

#2


1  

You'll have to use a webhost that supports Django. See https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts. Personally, I've used WebFaction and was quite happy with it, their support was great and customer service very responsive.

你必须使用支持Django的网络主机。见https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts。就我个人而言,我使用了weberge,我对它很满意,他们的支持很棒,客户服务也很响应。

#1


1  

Since your apache is shared, I don't expect you can change the httpd.conf but use instead your solution. My suggestion is:

由于您的apache是共享的,所以我不期望您可以更改httpd。同意,但用你的解决方案。我的建议是:

  1. If you have multiple servers you will deploy your project (e.g. testing, staging, production), then do the following steps for each deploy target.
  2. 如果您有多个服务器,您将部署您的项目(例如,测试、登台、生产),那么为每个部署目标执行以下步骤。
  3. In each server, create a true wsgi.py file which you will never put in versioning systems. Pretty much like you would do with a local_settings.py file. This file will be named wsgy.py since most likely you cannot edit the apache settings (since it is shared) and that name will be expected for your wsgi file.
  4. 在每个服务器中,创建一个真正的wsgi。py文件,在版本控制系统中永远不会出现。就像使用local_settings一样。py文件。这个文件将被命名为wsgy。由于大多数情况下您无法编辑apache设置(因为它是共享的),因此您的wsgi文件将需要这个名称。
  5. The content for the file will be:

    该文件的内容为:

     #!/path/to/your/virtualenv/python
     from my_true_wsgi import *
    

    Which will be different for each deploy server, but the difference will be, most likely, in the shebang line to locate the proper python interpreter.

    对于每个部署服务器,这是不同的,但是差异很可能出现在shebang行中,以定位合适的python解释器。

  6. You will have a file named my_true_wsgi to have it matching the import in the former code. That file will be in the versioning systems, unlike the wsgi.py file. The contents of such file is the usual contents of the wsgi.py on any regular django project, just that you are not using that name directly.
  7. 您将有一个名为my_true_wsgi的文件,它将匹配前一段代码中的导入。与wsgi不同,该文件将在版本控制系统中。py文件。此类文件的内容是wsgi的常见内容。对于任何常规的django项目,您都没有直接使用这个名称。

With this solution you can have several different wsgi files with no conflict on shebangs.

有了这个解决方案,您可以有几个不同的wsgi文件,而没有冲突的shebangs。

#2


1  

You'll have to use a webhost that supports Django. See https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts. Personally, I've used WebFaction and was quite happy with it, their support was great and customer service very responsive.

你必须使用支持Django的网络主机。见https://code.djangoproject.com/wiki/DjangoFriendlyWebHosts。就我个人而言,我使用了weberge,我对它很满意,他们的支持很棒,客户服务也很响应。