본문 바로가기

Computer/Python

flask 플라스크

 

sudo pip3 install Flask

 

sudo apt-get install apache2

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

sudo apt-get install php

 

sudo nano /var/www/heeseop/run.wsgi

import sys
sys.path.append("/var/www/heeseop")
from heeseop import app as application

* from heeseop is << heeseop means heeseop.py

 

sudo nano /var/www/heeseop/heeseop.py

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'

sudo nano /etc/apache2/apache2.conf

#For FLASK folder
<VirtualHost *:80>
  ServerName heeseop.com
    WSGIScriptAlias / /var/www/heeseop/run.wsgi
</VirtualHost>

#For another domain
<VirtualHost *:80>
  ServerName domian.com
  WSGIScriptAlias / /var/www/domain/run.wsgi
</VirtualHost>

#For PHP or HTML foler
<VirtualHost *:80>
  ServerName blog.com
  DocumentRoot /var/www/blog
</VirtualHost>

 

 

-------------------------------------------------------

ref

codingmonster.tistory.com/entry/%ED%95%98%EB%82%98%EC%9D%98-ip%EC%97%90-%EB%8F%84%EB%A9%94%EC%9D%B8-%EB%91%90%EA%B0%9C%EC%9D%B4%EC%83%81-%EC%97%B0%EA%B2%B0%ED%95%98%EA%B8%B0

 

 

 

더보기

-------------------------------------------------------

 

Virtual Environment

sudo pip install virtualenv

mkdir myproject
cd myproject
virtualenv venv

. venv/bin/activate

 

-------------------------------------------------------

Simple Demo - app.py

from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(0.0.0.0)

0.0.0.0 is several ip address in case of remote connection.

 

sudo nano /etc/apache2/sites-available/heeseop.conf<VirtualHost *:80> ServerName 192.168.50.216 WSGIDaemonProcess app threads=5 WSGIScriptAlias / /var/www/heeseop/run.wsgi DocumentRoot /var/www/heeseop <Directory /var/www/heeseop> WSGIProcessGroup app WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> ErrorLog /var/www/heeseop/logs/error.log LogLevel warn CustomLog /var/www/heeseop/logs/access.log combined </VirtualHost>

 

 

 

-------------------------------------------------------

 

Virtual Environment

sudo pip install virtualenv

mkdir myproject
cd myproject
virtualenv venv

. venv/bin/activate

 

-------------------------------------------------------

Simple Demo - app.py

from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return 'Hello World!' if __name__ == '__main__': app.run(0.0.0.0)

0.0.0.0 is several ip address in case of remote connection.

 

sudo nano /etc/apache2/sites-available/heeseop.conf<VirtualHost *:80> ServerName 192.168.50.216 WSGIDaemonProcess app threads=5 WSGIScriptAlias / /var/www/heeseop/run.wsgi DocumentRoot /var/www/heeseop <Directory /var/www/heeseop> WSGIProcessGroup app WSGIApplicationGroup %{GLOBAL} Order deny,allow Allow from all </Directory> ErrorLog /var/www/heeseop/logs/error.log LogLevel warn CustomLog /var/www/heeseop/logs/access.log combined </VirtualHost>

 

cd /etc/apache2/sites-available
sudo a2dissite 000-default
sudo a2ensite heeseop.conf
sudo service apache2 restart

 

 

 

 

'Computer > Python' 카테고리의 다른 글

Selenium  (0) 2022.06.07
SQLite3  (0) 2021.03.20
CGI  (0) 2020.04.25
Sqlite3  (0) 2020.04.24
Python Outline  (0) 2014.01.04