我正在设置django web应用程序,并使用github进行版本管理。所以我需要一个测试页面。我怎样才能做到这一点?
我发现了一个问题:Is it possible to host multiple django projects under the same domain?
但是它已经6岁了,我更愿意把它放在子域名下,我不知道答案是什么,因为我是Django的新手。
发布于 2019-02-19 17:54:05
是的,这是可能的。我在我的DigitalOcean液滴上运行了一个灯栈,托管了十几个live网站。所有这些都集中在站点配置中的虚拟环境设置上。
举个例子,如果你的学习足够让你去./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一样容易。
发布于 2019-02-19 17:45:39
如果您想要在同一台服务器上的子域上进行主机,我已经使用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‘替换为任何您想要的服务器。
https://stackoverflow.com/questions/54772038
复制相似问题