развертывание приложения django без субдомена

Я развернул django приложение на сервере, который я имею. Позвольте говорят, что его IP 192.168.1.1. Таким образом, я смог получить доступ к любому сайту там с 192.168.1.1/my_site.

Я теперь развернулся Django Приложение, которое является маленьким API. Я следую этому учебному руководству и использую апачей с mod_wsgi и с демоном. теперь проблема, когда я развернулся локально, я смог получить доступ к нему через localhost но все другие сайты не были доступны должные измениться в 000-default-000.conf файл.

Поскольку я развертываюсь в сервере, это возможный к доступу через IP и не будет конфликтовать с другими проектами в /var/www/html?

0
задан 25 October 2018 в 02:49

1 ответ

Не a Django + Apache эксперт, но найденный этим от сети, посмотрите, работает ли она на Вас.

Из django проекта

<VirtualHost *:80>
    # This is name based virtual hosting. So place an appropriate server name
    #   here. Example: django.devsrv.local
    ServerName  [[SERVER_NAME]]
    ServerAdmin webmaster@localhost

    # This alias makes serving static files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /static/  {{ project_directory }}/run/static/

    # This alias makes serving media files possible.
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    Alias /media/  {{ project_directory }}/run/media/

    # Insert the full path to the wsgi.py-file here
    WSGIScriptAlias /   {{ project_directory }}/{{ project_name }}/wsgi.py

    # PROCESS_NAME specifies a distinct name of this process
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIDaemonProcess
    # PATH/TO/PROJECT_ROOT is the full path to your project's root directory, 
    #   containing your project files
    # PATH/TO/VIRTUALENV/ROOT: If you are using a virtualenv specify the full
    #   path to its directory.
    #   Generally you must specify the path to Python's site-packages.
    WSGIDaemonProcess   {{ project_name }}  python-path={{ project_directory }}:{{ project_directory }}/../lib/python2.7/site-packages

    # PROCESS_GROUP specifies a distinct name for the process group
    #   see: https://code.google.com/p/modwsgi/wiki/ConfigurationDirectives#WSGIProcessGroup
    WSGIProcessGroup    {{ project_name }}

    # Serving static files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory {{ project_directory }}/run/static>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    # Serving media files from this directory
    #   Please note, that this is geared to our settings/common.py
    #   In production environment, you will propably adjust this!
    <Directory {{ project_directory }}/run/media>
        Options -Indexes
        Order deny,allow
        Allow from all
    </Directory>

    LogLevel warn

    # PROJECT_NAME is used to seperate the log files of this application
    ErrorLog    ${APACHE_LOG_DIR}/{{ project_name }}_error.log
    CustomLog   ${APACHE_LOG_DIR}/{{ project_name }}_access.log combined
</VirtualHost>

От металлической жабы

<VirtualHost *:80> 
 ServerName mysite.example.com 
 DocumentRoot /var/www/vhosts/mysite 
 WSGIScriptAlias / /var/www/vhosts/mysite/myproject/wsgi.py 

 # adjust the following line to match your Python path 
 WSGIDaemonProcess mysite.example.com processes=2 threads=15 display-name=%{GROUP} python-home=/var/www/vhosts/mysite/venv/lib/python3.5 
 WSGIProcessGroup mysite.example.com 

 <directory /var/www/vhosts/mysite> 
   AllowOverride all 
   Require all granted 
   Options FollowSymlinks 
 </directory> 

 Alias /static/ /var/www/vhosts/mysite/static/ 

 <Directory /var/www/vhosts/mysite/static> 
  Require all granted 
 </Directory> 
</VirtualHost> 

Металлическая Жаба идет далее, чтобы показать Вам, как настроить Ваш wsgi.py заставить это работать хорошо с apache:

"""
exposes the WSGI callable as a module-level variable named ``application``. 
For more information on this file, see 
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/ 
""" 
import os 
import time 
import traceback 
import signal 
import sys 

from django.core.wsgi import get_wsgi_application 

sys.path.append('/var/www/vhosts/mysite') 
# adjust the Python version in the line below as needed 
sys.path.append('/var/www/vhosts/mysite/venv/lib/python3.5/site-packages') 

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings") 

try: 
    application = get_wsgi_application() 
except Exception: 
    # Error loading applications 
    if 'mod_wsgi' in sys.modules: 
        traceback.print_exc() 
        os.kill(os.getpid(), signal.SIGINT) 
        time.sleep(2.5) 

Так играют вокруг с ним и заставляют его служить Вам. И Металлическая Жаба говорит, что можно даже установить несколько сайтов:

Второй Виртуальный Хост настраивается очень похоже к первому. Основными отличиями являются имена серверов, пути и местоположение wsgi.py файла.

0
ответ дан 27 October 2019 в 06:56

Другие вопросы по тегам:

Похожие вопросы: