【问题标题】:Install Django project on Ubuntu distant server在 Ubuntu 远程服务器上安装 Django 项目
【发布时间】:2017-06-16 16:04:13
【问题描述】:

我正在尝试将我的Django project 从我的 MacOSX 本地主机安装到 ubuntu 远程服务器。为了显示我的项目,我遇到了 Apache 的问题。

这是我已经完成的一些步骤:

  • 创建一个 IP 地址为 172.30.10.58 的 ubuntu 远程服务器
  • 将我的 Django 项目复制/粘贴到 /var/www/html/
  • 安装 Apache2
  • 安装所有 Django 模块(没关系,因为如果我运行 python manage.py runserver,我不会收到错误)

我遵循了一些教程:

所以我的 /etc/apache2/sites-available/000-defaut.conf 看起来像:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname and port that
        # the server uses to identify itself. This is used when creating
        # redirection URLs. In the context of virtual hosts, the ServerName
        # specifies what hostname must appear in the request's Host: header to
        # match this virtual host. For the default virtual host (this file) this
        # value is not decisive as it is used as a last resort host regardless.
        # However, you must set it for any further virtual host explicitly.
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html/etat_civil/


        Alias /static/ /var/www/html/etat_civil/BirthCertificate/static/
        Alias /uploads/ /secure_dir/uploads/

        WSGIDaemonProcess daemon-etat_civil user=www-data group=www-data processes=1 maximum-requests=1 threads=1 inactivity-timeout=6
        WSGIProcessGroup daemon-etat_civil
        WSGIScriptAlias / /var/www/html/etat_civil/Etat_civil/wsgi.py

        <Directory /var/www/html/etat_civil/Etat_civil>
                Order deny,allow
                Allow from all
        </Directory>

        <Location "/uploads/">
                SetHandler None
        </Location>

        ErrorLog /var/log/apache2/monprojet.error.log
        CustomLog /var/log/apache2/mystock.access.log combined

</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

然后,我运行:python manage.py runserver

我明白了:

ec@srvEC:/var/www/html/etat_civil$ python manage.py runserver
Performing system checks...

System check identified some issues:

WARNINGS:
?: (1_8.W001) The standalone TEMPLATE_* settings were deprecated in Django 1.8 and the TEMPLATES dictionary takes precedence. You must put the values of the following settings into your default TEMPLATES dict: TEMPLATE_DIRS.

System check identified 1 issue (0 silenced).
January 31, 2017 - 09:25:12
Django version 1.10.5, using settings 'Etat_civil.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

但是当我在浏览器中运行时:http://172.30.10.58 或其他东西,我得到:

你能帮我弄一个可以工作的 Django 项目吗?

谢谢

编辑:

日志文件:

[Tue Jan 31 11:12:47.052359 2017] [:error] [pid 7731] [remote 172.30.10.54:52913] mod_wsgi (pid=7731): Target WSGI script '/var/www/html/etat_civil/Etat_civil/wsgi.py' cannot be loaded as Python module.
[Tue Jan 31 11:12:47.052493 2017] [:error] [pid 7731] [remote 172.30.10.54:52913] mod_wsgi (pid=7731): Exception occurred processing WSGI script '/var/www/html/etat_civil/Etat_civil/wsgi.py'.
[Tue Jan 31 11:12:47.052529 2017] [:error] [pid 7731] [remote 172.30.10.54:52913] Traceback (most recent call last):
[Tue Jan 31 11:12:47.052560 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/var/www/html/etat_civil/Etat_civil/wsgi.py", line 16, in <module>
[Tue Jan 31 11:12:47.052660 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     application = get_wsgi_application()
[Tue Jan 31 11:12:47.052677 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 13, in get_wsgi_application
[Tue Jan 31 11:12:47.052727 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     django.setup(set_prefix=False)
[Tue Jan 31 11:12:47.052744 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 22, in setup
[Tue Jan 31 11:12:47.052793 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Tue Jan 31 11:12:47.052807 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 53, in __getattr__
[Tue Jan 31 11:12:47.052900 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     self._setup(name)
[Tue Jan 31 11:12:47.052917 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 41, in _setup
[Tue Jan 31 11:12:47.052940 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     self._wrapped = Settings(settings_module)
[Tue Jan 31 11:12:47.052951 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 97, in __init__
[Tue Jan 31 11:12:47.052968 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     mod = importlib.import_module(self.SETTINGS_MODULE)
[Tue Jan 31 11:12:47.052979 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]   File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Tue Jan 31 11:12:47.053042 2017] [:error] [pid 7731] [remote 172.30.10.54:52913]     __import__(name)
[Tue Jan 31 11:12:47.053070 2017] [:error] [pid 7731] [remote 172.30.10.54:52913] ImportError: No module named Etat_civil.settings

还有树形架构:

.
├── etat_civil
│   ├── Accueil
│   │   ├── admin.py
│   │   ├── admin.pyc
│   │   ├── apps.py
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── Base.css
│   │   │   └── images
│   │   │       ├── admin.png
│   │   │       ├── employé.png
│   │   │       ├── logo.png
│   │   │       ├── maire.png
│   │   │       ├── officier.png
│   │   │       └── visiteur.png
│   │   ├── templates
│   │   │   └── Accueil.html
│   │   ├── templatetags
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── user_tags.py
│   │   │   └── user_tags.pyc
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── views.py
│   │   └── views.pyc
│   ├── BirthCertificate
│   │   ├── admin.py
│   │   ├── admin.pyc
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── forms.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0001_initial.pyc
│   │   │   ├── __init__.py
│   │   │   └── __init__.pyc
│   │   ├── models.py
│   │   ├── models.pyc
│   │   ├── __pycache__
│   │   │   ├── admin.cpython-35.pyc
│   │   │   ├── countries.cpython-35.pyc
│   │   │   ├── forms.cpython-35.pyc
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── models.cpython-35.pyc
│   │   │   ├── sexe.cpython-35.pyc
│   │   │   ├── urls.cpython-35.pyc
│   │   │   └── views.cpython-35.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── BC_base.css
│   │   │   └── images
│   │   │       └── logo.jpeg
│   │   ├── templates
│   │   │   ├── BC_accueil.html
│   │   │   ├── BC_form.html
│   │   │   ├── BC_PDF.html
│   │   │   ├── BC_preview.html
│   │   │   ├── BC_raw2.html
│   │   │   ├── BC_raw.html
│   │   │   ├── BC_resume.html
│   │   │   └── Not_Found.html
│   │   ├── templatetags
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── user_tags.py
│   │   │   └── user_tags.pyc
│   │   ├── tests.py
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── views.py
│   │   └── views.pyc
│   ├── db.sqlite3
│   ├── Etat_civil
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── __pycache__
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── settings.cpython-35.pyc
│   │   │   ├── urls.cpython-35.pyc
│   │   │   └── wsgi.cpython-35.pyc
│   │   ├── settings.py
│   │   ├── settings.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── BC_base.css
│   │   │   └── images
│   │   │       ├── chantier.jpeg
│   │   │       ├── chantier.png
│   │   │       └── logo.png
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── wsgi.py
│   │   └── wsgi.pyc
│   ├── Identity
│   │   ├── admin.py
│   │   ├── admin.pyc
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── forms.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0001_initial.pyc
│   │   │   ├── __init__.py
│   │   │   └── __init__.pyc
│   │   ├── models.py
│   │   ├── models.pyc
│   │   ├── __pycache__
│   │   │   ├── admin.cpython-35.pyc
│   │   │   ├── countries.cpython-35.pyc
│   │   │   ├── forms.cpython-35.pyc
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── models.cpython-35.pyc
│   │   │   ├── sexe.cpython-35.pyc
│   │   │   ├── urls.cpython-35.pyc
│   │   │   └── views.cpython-35.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── Base.css
│   │   │   └── images
│   │   │       └── logo.png
│   │   ├── templates
│   │   │   ├── delete.html
│   │   │   ├── edit.html
│   │   │   ├── form_Identity.html
│   │   │   ├── Identity_home.html
│   │   │   ├── identity_resume.html
│   │   │   ├── preview.html
│   │   │   └── resume.html
│   │   ├── templatetags
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── user_tags.py
│   │   │   └── user_tags.pyc
│   │   ├── tests.py
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── views.py
│   │   └── views.pyc
│   ├── log
│   │   ├── admin.py
│   │   ├── admin.pyc
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── forms.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0001_initial.pyc
│   │   │   ├── __init__.py
│   │   │   └── __init__.pyc
│   │   ├── models.py
│   │   ├── models.pyc
│   │   ├── templates
│   │   │   └── connexion.html
│   │   ├── templatetags
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── user_tags.py
│   │   │   └── user_tags.pyc
│   │   ├── tests.py
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── views.py
│   │   └── views.pyc
│   ├── Mairie
│   │   ├── admin.py
│   │   ├── admin.pyc
│   │   ├── apps.py
│   │   ├── forms.py
│   │   ├── forms.pyc
│   │   ├── __init__.py
│   │   ├── __init__.pyc
│   │   ├── migrations
│   │   │   ├── 0001_initial.py
│   │   │   ├── 0001_initial.pyc
│   │   │   ├── __init__.py
│   │   │   └── __init__.pyc
│   │   ├── models.py
│   │   ├── models.pyc
│   │   ├── __pycache__
│   │   │   ├── admin.cpython-35.pyc
│   │   │   ├── countries.cpython-35.pyc
│   │   │   ├── forms.cpython-35.pyc
│   │   │   ├── __init__.cpython-35.pyc
│   │   │   ├── models.cpython-35.pyc
│   │   │   ├── sexe.cpython-35.pyc
│   │   │   ├── urls.cpython-35.pyc
│   │   │   └── views.cpython-35.pyc
│   │   ├── static
│   │   │   ├── css
│   │   │   │   └── Base.css
│   │   │   └── images
│   │   │       └── logo.png
│   │   ├── templates
│   │   │   ├── Mairie_form.html
│   │   │   ├── Mairie_home.html
│   │   │   └── Mairie_Resume.html
│   │   ├── templatetags
│   │   │   ├── __init__.py
│   │   │   ├── __init__.pyc
│   │   │   ├── user_tags.py
│   │   │   └── user_tags.pyc
│   │   ├── tests.py
│   │   ├── urls.py
│   │   ├── urls.pyc
│   │   ├── views.py
│   │   └── views.pyc
│   ├── manage.py
│   ├── media
│   │   └── logo.jpeg
│   ├── static
│   │   └── images
│   └── templates
│       ├── Base_Accueil.html
│       ├── Base_BirthCertificate.html
│       ├── Base_Identity.html
│       ├── Base_Mairie.html
│       └── Base_Not_Found.html
├── index.html
└── Individus

【问题讨论】:

  • 您在 apache 日志文件中有哪些错误?
  • 您告诉 apache 的配置文件该站点是 etat_civil.com,但您将浏览器带到 http://172.30.10.58。您是否设置了 DNS 路由和所有内容? ACNAME 之类的?
  • @AlexanderTyapkov 很奇怪,/var/log/apache2/monprojet.error.log中的日志文件是空的
  • @coralvanda 你说得对,我删除了关于 ServerName 和 ServerAlias 的两行,因为我暂时不想设置 DNS 路由^^
  • @Andro 你的 Apache 默认配置启用了吗?

标签: python django apache ubuntu


【解决方案1】:

在你的 apache 配置文件中导入 mod_wsgi 模块

/etc/apache2/sites-available/000-defaut.conf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-25
    • 2019-11-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多