繁体   English   中英

托管两个不同的项目django

[英]Host two different projects django

我正在设置一个Django Web应用程序,并且正在使用github进行版本管理。 所以我需要一个测试页面。 我该如何实现?

我发现了这个问题: 是否可以在同一域下托管多个Django项目?

但是它已经有6年的历史了,我宁愿将其托管在一个子域下,而且我也不知道答案在说什么,因为我是Django的新手。

对的,这是可能的。 我在我的DigitalOcean Droplet上运行了一个LAMP Stack,该Lamp Stack上托管着十多个实时Django网站。 所有这些实际上都集中在您的站点配置中的虚拟环境设置上。

这是一个例子,如果您的学习足以使您前进... /etc/apache2/sites-available/website1.com.conf

<VirtualHost *:80>

        ServerName website1.com
        ServerAlias www.website1.com

        ServerAdmin youremail@domain.com
        DocumentRoot /var/www/html/website1.com/djangoproject
        WSGIScriptAlias / /var/www/html/website1.com/djangoproject/djangoproject/wsgi.py

        WSGIDaemonProcess website1.com processes=2 threads=15 display-name=%{GROUP} \
                python-home=/var/www/html/website1.com/venv \
                python-path=/var/www/html/website1.com/ainet
        WSGIProcessGroup website1.com

        <Directory/var/www/html/website1.com/djangoproject>
                AllowOverride all
                Require all granted
                Options FollowSymlinks
        </Directory>

        Alias /static/ /var/www/html/website1.com/djangoproject/static/

        <Directory /var/www/html/website1.com/djangoproject/static/>
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

/etc/apache2/sites-available/website2.com.conf

<VirtualHost *:80>

        ServerName subdomain.website1.com
        ServerAlias subdomain.website1.com

        ServerAdmin youremail@domain.com
        DocumentRoot /var/www/html/subdomain.website1.com/djangoproject
        WSGIScriptAlias / /var/www/html/subdomain.website1.com/djangoproject/djangoproject/wsgi.py

        WSGIDaemonProcess subdomain.website1.com processes=2 threads=15 display-name=%{GROUP} \
                python-home=/var/www/html/subdomain.website1.com/venv \
                python-path=/var/www/html/subdomain.website1.com/ainet
        WSGIProcessGroup subdomain.website1.com

        <Directory/var/www/html/subdomain.website1.com/djangoproject>
                AllowOverride all
                Require all granted
                Options FollowSymlinks
        </Directory>

        Alias /static/ /var/www/html/subdomain.website1.com/djangoproject/static/

        <Directory /var/www/html/subdomain.website1.com/djangoproject/static/>
                Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>

以上假设您将django项目放在/var/www/html/website1.com/ 它还假定该文件夹包含位于venv文件夹中的虚拟环境。

/var/www/html/website1.com
/var/www/html/website1.com/djangoproject
/var/www/html/website1.com/venv
/var/www/html/subdomain.website1.com
/var/www/html/subdomain.website1.com/djangoproject
/var/www/html/subdomain.website1.com/venv

但是,如果您需要一个测试页面,那么Django有一个内置的本地开发服务器,我强烈建议您使用。

设置好环境后,就像运行python manage.py runserver一样简单。

如果您想在同一服务器的子域上进行托管,则可以使用Nginx作为反向代理。 设置非常容易,您可以将指向不同子域的请求指向运行django东西的任何服务器的不同实例。

看看这个: https//www.digitalocean.com/community/tutorials/how-to-configure-nginx-as-a-web-server-and-reverse-proxy-for-apache-on-one- ubuntu-14-04-droplet显然,您可以将“ apache”替换为所需的任何服务器。

暂无
暂无

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

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