2016-11-07 88 views
1

所以我一直在摸索我的頭,試圖找出這一個。我在Ubuntu 16.04上有兩個不同的django項目。這裏的意圖是在同一臺服務器上的兩個單獨的域上並排運行兩個不同的文件,這兩個文件位於「sites-(enabled | available)」文件夾中。一個工作正常(已經有一段時間了,這個第二個站點是新的)。第二個不是。我猜它必須與我的wsgi設置。讓事情變得複雜,我也使用let-encrypt。我相信那不是問題,但我會張貼他們的confs只是爲了確定。

項目一在目錄/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默認-LE-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-LE-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> 

有一些問題與導致服務器無法導入的myproject我的wsgi配置。但是,我不知道爲什麼這樣。這是違規的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/ 

沒有到目前爲止,我已經試過(我的谷歌是紫色鏈接的暗海)已成功地解決了這個問題對我來說。它不是權限,它不是組。它可以被導入到python中。我不明白是什麼導致它。

謝謝大家提前。

回答

3

您在兩個443 VirtualHost條目中缺少WSGIProcessGroup指令。對於這兩個請求都沒有被委派給正確的mod_wsgi守護進程組。由於Python模塊搜索路徑被設置爲守護進程組定義的一部分,因此它將無法找到您的應用程序代碼。

+0

謝謝格雷厄姆抓住那個。 mod_wsgi先生本人:)回想起來似乎很明顯,但是由於LetsEncrypt腳本將它們取出,所以我不想「插手」。將其標記爲接受的答案。 – arlyon

相關問題