2016-11-07 4 views
1

Так что я немного почесываю голову, пытаясь понять это. Я на Ubuntu 16.04, с двумя различными проектами django. Цель состоит в том, чтобы запустить обе бок о бок на двух отдельных доменах на одном сервере, используя два разных файла в папке «sites- (enabled | available)». Один работает отлично (и был на некоторое время, этот второй сайт является новым). Второе - нет. Я предполагаю, что это связано с моими настройками wsgi. Чтобы усложнить ситуацию, я также использую let-encrypt. Я уверен, что это не проблема, но я буду публиковать их конфиги, чтобы быть уверенными.

Проект один находится в каталоге /home/arlyon/arlyon и nr2 находится в каталоге /home/arlyon/threeswords.

000-default.conf

<VirtualHost *:80> 

    ServerName www.site1.com 
    ServerAlias site1.com 
    ServerAdmin [email protected] 
    DocumentRoot /home/arlyon/arlyon 

    WSGIScriptAlias//home/arlyon/arlyon/arlyon/apache/wsgi.py 
    WSGIDaemonProcess arlyon python-home=/home/arlyon/arlyon/venv python-path=/home/arlyon/arlyon 
    WSGIProcessGroup arlyon 


    Alias /static/ /home/arlyon/arlyon/static/ 
    <Directory /home/arlyon/arlyon/static> 
      Require all granted 
    </Directory> 

    Alias /media/ /home/arlyon/arlyon/media/ 
    <Directory /home/arlyon/arlyon/media> 
      Require all granted 
    </Directory> 

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

    RewriteEngine on 
    RewriteCond %{SERVER_NAME} =www.site1.com 
    RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] 

    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC] 
    RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

</VirtualHost> 

000-умолчанию-ле-SSL

<IfModule mod_ssl.c> 
<VirtualHost *:443> 

    ServerName www.site1.com 
    ServerAlias site1.com 
    ServerAdmin [email protected] 
    DocumentRoot /home/arlyon/arlyon 

    # user/project/projectapp 
    # project and home dir are the same 

    WSGIScriptAlias//home/arlyon/arlyon/arlyon/apache/wsgi.py 
    Alias /static/ /home/arlyon/arlyon/static/ 
    <Directory /home/arlyon/arlyon/static> 
      Require all granted 
    </Directory> 

    Alias /media/ /home/arlyon/arlyon/media/ 
    <Directory /home/arlyon/arlyon/media> 
      Require all granted 
    </Directory> 


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

    SSLCertificateFile /etc/letsencrypt/live/www.site1.com/fullchain.pem 
    SSLCertificateKeyFile /etc/letsencrypt/live/www.site1.com/privkey.pem 
    Include /etc/letsencrypt/options-ssl-apache.conf 

</VirtualHost> 
</IfModule> 

site2.conf

<VirtualHost *:80> 

    ServerName www.site2.com 
    ServerAlias *.site2.com 
    ServerAdmin [email protected] 
    DocumentRoot /home/arlyon/threeswords 

    WSGIScriptAlias//home/arlyon/threeswords/threeswords/wsgi.py 
    WSGIDaemonProcess threeswords python-path=/home/arlyon/threeswords python-home=/home/arlyon/threeswords/venv 
    WSGIProcessGroup threeswords 

    <Directory "/home/arlyon/threeswords/threeswords/"> 
      <Files wsgi.py> 
        Require all granted 
      </Files> 
    </Directory> 

    Alias /static/ /home/arlyon/threeswords/static/ 
    <Directory /home/arlyon/threeswords/static> 
      Require all granted 
    </Directory> 

    Alias /media/ /home/arlyon/threeswords/media/ 
    <Directory /home/arlyon/threeswords/media> 
      Require all granted 
    </Directory> 

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

    RewriteEngine on 
    RewriteCond %{SERVER_NAME} =www.site2.no [OR] 
    RewriteCond %{SERVER_NAME} =*.site2.no 
    RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] 

</VirtualHost> 

threeswords-ле-ssl.conf

<IfModule mod_ssl.c> 
<VirtualHost *:443> 

    ServerName www.site2.no 
    ServerAlias *.site2.no 
    ServerAdmin [email protected] 
    DocumentRoot /home/arlyon/threeswords 

    WSGIScriptAlias//home/arlyon/threeswords/threeswords/wsgi.py 

    Alias /static/ /home/arlyon/threeswords/static/ 
    <Directory /home/arlyon/threeswords/static> 
     Require all granted 
    </Directory> 

    Alias /media/ /home/arlyon/threeswords/media/ 
    <Directory /home/arlyon/threeswords/media> 
     Require all granted 
    </Directory> 

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

    RewriteEngine on 
    RewriteCond %{SERVER_NAME} =www.site2.no 
    # Some rewrite rules in this file were were disabled on your HTTPS site, 
    # because they have the potential to create redirection loops. 
    # RewriteRule^https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent] 

    RewriteCond %{HTTPS} !=on 
    RewriteCond %{HTTP_HOST} !^www\..+$ [NC] 
    RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

    SSLCertificateFile /etc/letsencrypt/live/www.site1.com/fullchain.pem 
    SSLCertificateKeyFile /etc/letsencrypt/live/www.site1.com/privkey.pem 
    Include /etc/letsencrypt/options-ssl-apache.conf 

</VirtualHost> 
</IfModule> 

Существует некоторая проблема с моей WSGI конфигурации, который вызывает сервер, чтобы не быть в состоянии импортировать MyProject. Однако я понятия не имею, почему так. Вот оскорбительный wsgi.py.

from __future__ import absolute_import, unicode_literals 
import site 
import os 

from django.core.wsgi import get_wsgi_application 

site.addsitedir('/home/arlyon/threeswords/venv/lib/python3.5/site-packages') 
os.environ["DJANGO_SETTINGS_MODULE"] = "threeswords.settings.dev" 

application = get_wsgi_application() 

Venv указывает на нужное место. При попытке установить модуль настроек он выдает ошибку импорта . Наконец здесь ошибка:

[Mon Nov 07 23:27:29.484760 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] mod_wsgi (pid=30535): Target WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py' cannot be loaded as Python module. 
[Mon Nov 07 23:27:29.484844 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] mod_wsgi (pid=30535): Exception occurred processing WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py'. 
[Mon Nov 07 23:27:29.485206 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] Traceback (most recent call last): 
[Mon Nov 07 23:27:29.485321 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/home/arlyon/threeswords/threeswords/wsgi.py", line 19, in <module> 
[Mon Nov 07 23:27:29.485349 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  application = get_wsgi_application() 
[Mon Nov 07 23:27:29.485369 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application 
[Mon Nov 07 23:27:29.485379 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  django.setup() 
[Mon Nov 07 23:27:29.485397 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 17, in setup 
[Mon Nov 07 23:27:29.485407 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  configure_logging(settings.LOGGING_CONFIG, settings.LOGGING) 
[Mon Nov 07 23:27:29.485425 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 55, in __getattr__ 
[Mon Nov 07 23:27:29.485435 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  self._setup(name) 
[Mon Nov 07 23:27:29.485452 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 43, in _setup 
[Mon Nov 07 23:27:29.485462 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  self._wrapped = Settings(settings_module) 
[Mon Nov 07 23:27:29.485480 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 99, in __init__ 
[Mon Nov 07 23:27:29.485489 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  mod = importlib.import_module(self.SETTINGS_MODULE) 
[Mon Nov 07 23:27:29.485507 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module 
[Mon Nov 07 23:27:29.485517 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377]  return _bootstrap._gcd_import(name[level:], package, level) 
[Mon Nov 07 23:27:29.485534 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
[Mon Nov 07 23:27:29.485554 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
[Mon Nov 07 23:27:29.485573 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked 
[Mon Nov 07 23:27:29.485592 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
[Mon Nov 07 23:27:29.485612 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
[Mon Nov 07 23:27:29.485631 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
[Mon Nov 07 23:27:29.485650 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked 
[Mon Nov 07 23:27:29.485669 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed 
[Mon Nov 07 23:27:29.485688 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 986, in _gcd_import 
[Mon Nov 07 23:27:29.485707 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 969, in _find_and_load 
[Mon Nov 07 23:27:29.485736 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked 
[Mon Nov 07 23:27:29.485774 2016] [wsgi:error] [pid 30535:tid 140472987141888] [client 92.221.32.65:56377] ImportError: No module named 'threeswords' 
[Mon Nov 07 23:27:29.700491 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] mod_wsgi (pid=30535): Target WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py' cannot be loaded as Python module., referer: https://www.site2.no/ 
[Mon Nov 07 23:27:29.700569 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] mod_wsgi (pid=30535): Exception occurred processing WSGI script '/home/arlyon/threeswords/threeswords/wsgi.py'., referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.700934 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] Traceback (most recent call last):, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701050 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/home/arlyon/threeswords/threeswords/wsgi.py", line 19, in <module>, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701061 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  application = get_wsgi_application(), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701081 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701091 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  django.setup(), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701110 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/__init__.py", line 17, in setup, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701120 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  configure_logging(settings.LOGGING_CONFIG, settings.LOGGING), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701139 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 55, in __getattr__, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701149 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  self._setup(name), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701183 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 43, in _setup, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701193 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  self._wrapped = Settings(settings_module), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701212 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/local/lib/python3.5/dist-packages/django/conf/__init__.py", line 99, in __init__, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701222 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  mod = importlib.import_module(self.SETTINGS_MODULE), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701240 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701250 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378]  return _bootstrap._gcd_import(name[level:], package, level), referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701285 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701306 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701326 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701346 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701366 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701386 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701405 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 944, in _find_and_load_unlocked, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701425 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701445 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 986, in _gcd_import, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701465 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 969, in _find_and_load, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701484 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] File "<frozen importlib._bootstrap>", line 956, in _find_and_load_unlocked, referer: https://www.site2.com/ 
[Mon Nov 07 23:27:29.701523 2016] [wsgi:error] [pid 30535:tid 140472978749184] [client 92.221.32.65:56378] ImportError: No module named 'threeswords', referer: https://www.site2.com/ 

Ничего я пытался до сих пор (мой Google не является темным морем фиолетовых ссылки) удалось решить эту проблему для меня. Это не разрешения, это не группа. Его можно импортировать в python просто отлично. Я не понимаю, что вызывает это.

Благодарим вас заблаговременно.

ответ

3

Вам не хватает директивы WSGIProcessGroup в обеих ваших 443 VirtualHost материалах. Для обоих из них запросы не передаются в правильную группу процессов daemon mod_wsgi. Поскольку путь поиска модуля Python настраивается как часть определения группы процессов демона, он не сможет найти ваш код приложения.

+0

Спасибо, Грэхем за то, что он поймал это. Сам г-н mod_wsgi :) Это кажется очевидным в ретроспективе, но поскольку сценарий LetsEncrypt вынул их, я не хотел «вмешиваться». Отмечено это как принятый ответ. – arlyon

 Смежные вопросы

  • Нет связанных вопросов^_^