bbgo 문서

bbgo 문서 및 가이드 뒤로가기
bbgo + apache 사이트 구축하기
gencode.me
3640 0
2017-12-27 23:27:09
https://gencode.me/6/
125.178.*.*
2019-08-22 22:52:08

로컬에서 개발중에 테스트할 때는 ./runlocalserver.sh 를 이용하면 되지만 실제 서버에서 운용시에는 아파치를 이용하는게 정석입니다.


아래는 우분투 14.04 + apache + wsgi (+ SSL) + virtualenv 기준의 예입니다. 그외의 환경은 아래 장고 공식 문서를 참고하세요.

How to use Django with Apache and mod_wsgi

How to use Django with Gunicorn

How to use Django with uWSGI

mod_wsgi 설치


우선 아파치에서 장고를 사용하려면 mod_wsgi 를 설치해야 합니다.

$ sudo apt-get install libapache2-mod-wsgi


apache 설정


  • http:// 로 배포시

        - /etc/apache2/sites-available/000-default.conf 파일에 아래 내용 추가

        - <domain>, <project path>, <virtualenv path>은 본인의 설정에 맞게 변경

<VirtualHost *:80>
        ServerName <domain>
        WSGIDaemonProcess bbgo python-home=<virtualenv path>/lib/python2.7/site-packages
        WSGIProcessGroup bbgo
        WSGIScriptAlias / <project path>/bbgo/apache/wsgi.py
        WSGIApplicationGroup %{GLOBAL}

        <Directory "<project path>/bbgo/apache/">
            <Files wsgi.py>
                Require all granted 
            </Files>
        </Directory>

        Alias /static/admin <virtualenv path>/lib/python2.7/site-packages/django/contrib/admin/static/admin/
        <Directory "<virtualenv path>/lib/python2.7/site-packages/django/contrib/admin/static/admin/">
                Require all granted
        </Directory>
        Alias /static/summernote <virtualenv path>/lib/python2.7/site-packages/django_summernote/static/summernote/
        <Directory "<virtualenv path>/lib/python2.7/site-packages/django_summernote/static/summernote/">
                Require all granted
        </Directory>
        Alias /static/ <project path>/static/
        <Directory "<project path>/static/">
                Require all granted
        </Directory>
        Alias /upload/ <project path>/upload/
        <Directory "<project path>/upload/">
                Require all granted
        </Directory>
</VirtualHost>


  • https:// 로 배포시 (SSL)

        - /etc/apache2/sites-available/default-ssl.conf 파일에 아래 내용 추가

        - <domain>, <virtualenv path>, <project path>, <cert path> 등은 본인의 환경에 맞게 설정

<IfModule mod_ssl.c>
        <VirtualHost _default_:443>
                ServerName <domain>

                WSGIDaemonProcess bbgo python-home=<virtualenv path>/lib/python2.7/site-packages
                WSGIProcessGroup bbgo
                WSGIScriptAlias / <project path>/bbgo/apache/wsgi.py
                WSGIApplicationGroup %{GLOBAL}

                <Directory "<project path>/bbgo/apache/">
                    <Files wsgi.py>
                        Require all granted 
                    </Files>
                </Directory>

                Alias /static/admin <virtualenv path>/lib/python2.7/site-packages/django/contrib/admin/static/admin/
                <Directory "<virtualenv path>/lib/python2.7/site-packages/django/contrib/admin/static/admin/">
                        Require all granted
                </Directory>
                Alias /static/summernote <virtualenv path>/lib/python2.7/site-packages/django_summernote/static/summernote/
                <Directory "<virtualenv path>/lib/python2.7/site-packages/django_summernote/static/summernote/">
                        Require all granted
                </Directory>
                Alias /static/ <project path>/static/
                <Directory "<project path>/static/">
                        Require all granted
                </Directory>
                Alias /upload/ <project path>/upload/
                <Directory "<project path>/upload/">
                        Require all granted
                </Directory>

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

                SSLEngine on

                SSLCertificateFile <cert path>
                SSLCertificateKeyFile <certkey path>
                SSLCertificateChainFile <cert chain path>
                SSLCACertificateFile <rootCA path>

                BrowserMatch "MSIE [2-6]" \
                                nokeepalive ssl-unclean-shutdown \
                                downgrade-1.0 force-response-1.0
                BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown
        </VirtualHost>

</IfModule>


        - SSL enable

$ sudo a2enmod ssl
$ sudo a2ensite default-ssl


  • 아파치 재시작

        - 서버에 수정사항을 적용한 후에도 아파치를 재시작해 줘야 제대로 반영됩니다.

$ sudo service apache2 restart
비추 공유
댓글 [ 8 ]
asdf 04-11
클리앙이 이거 쓰는거 맞나요?
gencode.me 04-11
asdf
아닙니다.
borring 11-07
bbgo 개발자님.
해당 아파치 설정 후 아파치 로그를 보면 "bbgo.settings"를 import하지 못하는 에러가 발생합니다.
수정해야 할 부분이 있으면 알려주시면 감사하겠습니다.
gencode.me 11-08
borring
아파치 설정에서 경로를 재확인해 보시기 바랍니다.
borring 11-08
gencode.me
------------/etc/apache2/sites-available/000-default.conf -------------------------
<VirtualHost *:80>
ServerName bbgo
WSGIDaemonProcess bbgo python-home= /home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages
WSGIProcessGroup bbgo
WSGIScriptAlias / /home/bbgo/bbgo/bbgo/apache/wsgi.py

<Directory "/home/bbgo/bbgo/bbgo/apache/">
Require all granted
</Directory>

Alias /static/admin /home/bbgo/bbgo/lib/python2.7/site-packages/django/contrib/admin/static/admin/
<Directory "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django/contrib/admin/static/admin/">
Require all granted
</Directory>
Alias /static/summernote /home/bbgo/bbgo/lib/python2.7/site-packages/django_summernote/static/summernote/
<Directory "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django_summernote/static/summernote/">
Require all granted
</Directory>
Alias /static/ /home/bbgo/bbgo/static/
<Directory "/home/bbgo/bbgo/static/">
Require all granted
</Directory>
Alias /upload/ /home/bbgo/bbgo/upload/
<Directory "/home/bbgo/bbgo/upload/">
Require all granted
</Directory>
</VirtualHost>
borring 11-08
-----------------아파치 경로-----------------------
(bbgo) bbgo@bbgo:~/bbgo/bbgo/apache$ pwd
/home/bbgo/bbgo/bbgo/apache

------------------------파이썬 경로------------------------------
(bbgo) bbgo@bbgo:/$ python -m site
sys.path = [
'/',
'/home/bbgo/.pyenv/versions/bbgo/lib/python27.zip',
'/home/bbgo/.pyenv/versions/bbgo/lib/python2.7',
'/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/plat-linux2',
'/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/lib-tk',
'/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/lib-old',
'/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/lib-dynload',
'/home/bbgo/.pyenv/versions/2.7.13/lib/python2.7',
'/home/bbgo/.pyenv/versions/2.7.13/lib/python2.7/plat-linux2',
'/home/bbgo/.pyenv/versions/2.7.13/lib/python2.7/lib-tk',
'/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages',
]
borring 11-08
(bbgo) bbgo@bbgo:~/bbgo/bbgo/apache$ python wsgi.py
Traceback (most recent call last):
File "wsgi.py", line 23, in <module>
application = get_wsgi_application()
File "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django/core/wsgi.py", line 13, in get_wsgi_application
django.setup(set_prefix=False)
File "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django/__init__.py", line 22, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django/conf/__init__.py", line 56, in __getattr__
self._setup(name)
File "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django/conf/__init__.py", line 41, in _setup
self._wrapped = Settings(settings_module)
File "/home/bbgo/.pyenv/versions/bbgo/lib/python2.7/site-packages/django/conf/__init__.py", line 110, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/home/bbgo/.pyenv/versions/2.7.13/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
ImportError: No module named bbgo.settings



경로가 잘못된거같진 않은데..Import에러가 발생합니다 수정부분 봐주시면 감사하겠습니다
borring 11-08
(bbgo) bbgo@bbgo:~/bbgo/bbgo/apache$ pip freeze
asn1crypto==0.24.0
certifi==2018.1.18
cffi==1.11.4
chardet==3.0.4
cryptography==2.3
Django==1.11.15
django-appconf==1.0.2
django-fernet-fields==0.5
django-rosetta==0.8.1
django-statici18n==1.7.0
django-summernote==0.8.8.5
enum34==1.1.6
idna==2.6
ipaddress==1.0.19
microsofttranslator==0.8
Pillow==5.0.0
polib==1.1.0
psycopg2==2.7.3.2
pycparser==2.18
pytz==2017.3
requests==2.20.0
six==1.11.0
urllib3==1.22