wilson's story

[ubuntu18.04] Apache2 + Python3 + WSGI 본문

Python

[ubuntu18.04] Apache2 + Python3 + WSGI

wilson 2020. 5. 12. 15:24
반응형

ubuntu18.04 버전 기준입니다

ubuntu18.04의 기본 python버전은 3.6으로 세팅되어있습니다

 

sudo apt-get install apache2
sudo apt-get install libapache2-mod-wsgi-py3

sudo a2enmod wsgi 

 

cd /etc/apache2/sites-available

vi 000-default.conf

<VirtualHost *:5003> 
   
 
    ErrorLog /workspace/service/WebServer/log/error.log 
    CustomLog /workspace/service/WebServer/log/access.log combined 
 
 
   WSGIDaemonProcess WebServerApp threads=10 python-path=/workspace/service/WebServer 
   WSGIProcessGroup WebServerApp 
   WSGIScriptAlias / /workspace/service/WebServer/app.wsgi 
   Alias /static/ /workspace/service/WebServer/static/ 
   <Directory /workspace/service/WebServer/> 
        Order allow,deny 
        Allow from all 
   </Directory> 
 
</VirtualHost>

 

cd /etc/apache2

vi apache2.conf  하단에 Directory 에 추가 해준다 Require all granted 는 해당 경로의 권한을 열어준다는 듯

<Directory /workspace/service/WebServer/> 
    Require all granted 
</Directory>

 

vi ports.conf 에 추가, 사용하려는 포트를 추가해준다

Listen 5003

 

프로젝트 위치로 이동 (/workspace/service/WebServer)

app.wsgi 파일 생성 

  import sys 
  sys.path.insert(0,"/workspace/service/") 
  from WebServer import app as application

 

동일한 위치에 Flask 실행 메인 파일 이름을 __init__.py 로 변경해준다

예) cp app.py __init__.py

 

app.wsgi 은 __init__.py 을 읽어 들여서 구동된다

 

apache를 재기동해준다

sudo /etc/init.d/apache2 restart

 

추가사항

 - 프로젝트 폴더권한은 최소 655 이상 으로 변경해준다

 - 000-default.conf 파일을 사용안하고 신규 *.conf를 사용하려고 한다면 

신규 *.conf를 생성하고 

 

a2ensite WebServer2.conf

적용하고 apache를 재기동 시켜줘야한다

 

 

반응형