简体   繁体   English

在 ubuntu apache2 上部署 django 应用程序

[英]Deploy django app on ubuntu apache2

I want to run my Django app created in virtualenv on ubuntu with python3.我想用 python3 在 ubuntu 上运行我在 virtualenv 中创建的 Django 应用程序。 Folder structure in virtualenv folder: virtualenv 文件夹中的文件夹结构:

-bin -垃圾桶

-include -包括

-lib -lib

-myapp -myapp

-share -分享

pip-selfcheck.json pip-selfcheck.json

The myapp folder contains my application with apache folder configured as specified in this tutorial: https://www.sitepoint.com/deploying-a-django-app-with-mod_wsgi-on-ubuntu-14-04/ I have all apps installed I need in my virtualenv, after 'sudo service apache2 restart' I see only Apache2 Ubuntu Default Page. myapp 文件夹包含我的应用程序,其中配置了本教程中指定的 apache 文件夹: https ://www.sitepoint.com/deploying-a-django-app-with-mod_wsgi-on-ubuntu-14-04/ 我有所有应用程序在我的 virtualenv 中安装了我需要的,在“sudo service apache2 restart”之后,我只看到 Apache2 Ubuntu 默认页面。 File /etc/apache2/sites-enabled/000-default.conf is like in the tutorial:文件 /etc/apache2/sites-enabled/000-default.conf 就像教程中一样:

<VirtualHost *:80>
    WSGIScriptAlias / /home/myuser/mysite/apache/wsgi.py
    <Directory "/home/myuser/mysite/apache/">
      Require all granted
    </Directory>
</VirtualHost>

Of course with correct paths pointing to my project location in 'venv' folder.当然,正确的路径指向我在“venv”文件夹中的项目位置。 No idea where to move on, what to check, thanks for suggestions.不知道从哪里继续,检查什么,感谢您的建议。

EDIT: I realy dont get this, I edited the mentioned file, had a try, nothing happened so I edited it back and after restart it it worked.编辑:我真的不明白,我编辑了提到的文件,试了一下,什么也没发生,所以我重新编辑它,重新启动后它工作了。

The official Django documentation on using mod_wsgi can be found at:关于使用 mod_wsgi 的官方 Django 文档可以在以下位置找到:

It may be better to consult that for how to set things up specifically for Django, you are missing various required configuration elements.最好咨询一下如何专门为 Django 进行设置,因为您缺少各种必需的配置元素。

As to why you are still getting the default page, it could be because you added that configuration as an extra thing to the end of the default sites file, rather than inserting the contents of the VirtualHost you have into the existing VirtualHost in that file.至于为什么您仍然获得默认页面,可能是因为您将该配置作为额外的东西添加到默认站点文件的末尾,而不是将您拥有的VirtualHost的内容插入到该文件中的现有VirtualHost中。 If you added it after, it will be ignored as it will still use the existing VirtualHost as it comes first and you haven't set up correctly named based hosting.如果您在之后添加它,它将被忽略,因为它仍然会使用现有的VirtualHost ,因为它首先出现并且您没有正确设置基于命名的托管。

Also be aware that where other people say you should use something else, every solution will have a learning curve if this is all new.另请注意,在其他人说您应该使用其他东西的地方,如果这是全新的,每个解决方案都会有一个学习曲线。 No solution is simple if you want to integrate into your existing host system.如果您想集成到现有的主机系统中,任何解决方案都不是简单的。 So jumping around looking at different solutions can be a great waste of time.因此,四处寻找不同的解决方案可能会浪费大量时间。 Select one which you think you like and stick with it.选择一个你认为你喜欢的并坚持下去。 The idea that one is superior to others is in general nonsense as their performance is similar.一个人优于其他人的想法通常是无稽之谈,因为他们的表现相似。

I would actually suggest you skip even trying to integrate it into your host system to begin with if you are just playing.实际上,如果您只是在玩游戏,我实际上建议您跳过甚至尝试将其集成到您的主机系统中。 Use a WSGI server that you can run from the command line, even if it is just the bundled development server with Django.使用可以从命令行运行的 WSGI 服务器,即使它只是与 Django 捆绑的开发服务器。 Options which are simple to run from the command line are:可以从命令行简单运行的选项是:

So after editing the file, restarting apache, editing the file back it works (/etc/apache2/sites-enabled/000-default.conf).因此,在编辑文件后,重新启动 apache,重新编辑文件,它就可以工作了(/etc/apache2/sites-enabled/000-default.conf)。 Really dont get it, several restarts yesterday did not help...真的不明白,昨天重启了几次都没有用……

I have Ubuntu 20.04 and Apache2.我有 Ubuntu 20.04 和 Apache2。 I followed the mod_wsgi installation instructions linked to here but forgot to enable the module in /etc/apache2/apache2.conf (or to include a file from apache2.conf that does so).我按照链接到此处的 mod_wsgi 安装说明进行操作,但忘记在/etc/apache2/apache2.conf中启用该模块(或包含来自 apache2.conf 的文件)。 I added that and then the WSGIScriptAlias / /home/myuser/mysite/apache/wsgi.py directive in my 000-default.conf did not cause an error when I restarted the server with systemctl restart apache2我添加了它,然后当我使用systemctl restart apache2重新启动服务器时,我的 000-default.conf 中的WSGIScriptAlias / /home/myuser/mysite/apache/wsgi.py指令没有导致错误

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM