在Apache for Django 1.10上的共享宿主设置

2024-10-01 19:23:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我们正在寻找一种干净和孤立的方式,在一个Apache上托管多个Django站点,在Ubuntu14.04上使用vhosts。在

遵循文档https://docs.djangoproject.com/en/1.10/howto/deployment/wsgi/modwsgi/#using-mod-wsgi-daemon-mode 并且Where should WSGIPythonPath point in my virtualenv?,我们设置了以下设置:

为mod帴wsgi提供全球虚拟化服务

virtualenv -p /usr/bin/python3 /home/admin/vhosts_venv
. vhosts_venv/bin/activate
pip install mod-wsgi

sudo /home/admin/vhosts_venv/bin/mod_wsgi-express install-module
sudo vi /etc/apache2/mods-available/wsgi_express.load

添加:

^{pr2}$

然后有一个vhost venv和一个基本应用程序:

virtualenv -p /usr/bin/python3 /home/admin/vhost1_venv
. vhost1_venv/bin/activate
pip install Django
pip install PyMySQL

django-admin startproject vhost1
cd vhost1
python manage.py startapp main

设置主机分辨率:

sudo vi /etc/hosts

更新时间:

127.0.0.1       localhost vhost1.example.com

安装Apache vhost时使用:

<VirtualHost vhost1.example.com:80>
  ServerName vhost1.example.com
  ServerAlias example.com
  ServerAdmin webmaster@localhost
  #DocumentRoot /var/www/html

  ErrorLog ${APACHE_LOG_DIR}/vhost1_error.log
  CustomLog ${APACHE_LOG_DIR}/vhost1_access.log combined

  WSGIProcessGroup  vhost1.example.com
  WSGIScriptAlias / /home/admin/vhost1/vhost1/wsgi.py process-group=vhost1.example.com
  WSGIDaemonProcess vhost1.example.com user=www-data group=www-data threads=25 python-path=/home/admin/vhost1:/home/admin/vhost1_venv/lib/python3.4/site-packages:/home/admin/vhosts_venv/lib/python3.4/site-packages

  <Directory /home/admin/vhost1>
    <Files wsgi.py>
      <IfVersion < 2.3>
        Order deny,allow
        Allow from all
      </IfVersion>
      <IfVersion >= 2.3>
        Require all granted
      </IfVersion>
    </Files>
  </Directory>

</VirtualHost>

启用所有功能:

sudo a2enmod wsgi_express
sudo a2ensite vhost1
sudo service apache2 restart

在测试它时,我们会为一个curl请求得到2个答案,在2个时间段内交付(每个时间间隔大约0.5秒):

curl vhost1.example.com

It worked! Congratulations on your first Django-powered page.

Of course, you haven't actually done any work yet. Next, start your first app by running python manage.py startapp [app_label].

You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!

后接:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log. Apache/2.4.7 (Ubuntu) Server at vhost1.example.com Port 80

/var/log/apache2/error.log中,我们得到:

[Mon Aug 15 15:37:42.754139 2016] [core:notice] [pid 18622:tid 140151787534208] AH00051: child pid 18717 exit signal Segmentation fault (11) , possible coredump in /etc/apache2

/var/log/apache2/vhost1_access.log中:

127.0.0.1 - - [15/Aug/2016:15:37:42 +0200] "GET / HTTP/1.1" 500 2593 "-" "curl/7.35.0"

如何正确设置?在


Tags: djangocomlogmodwsgihomebinvenv
1条回答
网友
1楼 · 发布于 2024-10-01 19:23:28

对格雷多姆的回答进行总结

/etc/apache2/mods-available/wsgi_express.conf看起来像:

WSGIRestrictEmbedded On

/etc/apache2/sites-available/vhost1.conf看起来像:

^{pr2}$

相关问题 更多 >

    热门问题