This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
язык_программирования_python [2024/12/02 12:56] val [Web приложение] |
язык_программирования_python [2025/03/16 11:44] (current) val [Web приложение] |
||
---|---|---|---|
Line 23: | Line 23: | ||
* [[https://python.ivan-shamaev.ru/run-install-deploy-flask-web-app-docker-dockerfile-compose/|Создание Web-приложения Flask и деплой с помощью Docker Compose & Dockerfile]] | * [[https://python.ivan-shamaev.ru/run-install-deploy-flask-web-app-docker-dockerfile-compose/|Создание Web-приложения Flask и деплой с помощью Docker Compose & Dockerfile]] | ||
* [[https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https|Running Your Flask Application Over HTTPS]] | * [[https://blog.miguelgrinberg.com/post/running-your-flask-application-over-https|Running Your Flask Application Over HTTPS]] | ||
+ | * [[https://docs.python.org/3/library/configparser.html|configparser — Configuration file parser]] | ||
* [[#Виртуальная среда Python]] | * [[#Виртуальная среда Python]] | ||
Line 36: | Line 37: | ||
import os | import os | ||
import configparser | import configparser | ||
- | |||
- | CONST_VER = "ver1.4" | ||
app = Flask(__name__) | app = Flask(__name__) | ||
Line 53: | Line 52: | ||
config = configparser.ConfigParser() | config = configparser.ConfigParser() | ||
config.read('/etc/pywebd/pywebd.conf') | config.read('/etc/pywebd/pywebd.conf') | ||
- | pywebd_port = os.environ.get('PYWEBD_PORT',config['default']['Listen']) | + | # pywebd_port = os.environ.get('PYWEBD_PORT',config['default']['Listen']) |
- | pywebd_doc_root = os.environ.get('PYWEBD_DOC_ROOT',config['default']['DocumentRoot']) | + | # pywebd_doc_root = os.environ.get('PYWEBD_DOC_ROOT',config['default']['DocumentRoot']) |
- | app.run(ssl_context=('/etc/pywebd/pywebd.crt', '/etc/pywebd/pywebd.key'), debug=True, host='0.0.0.0', port=pywebd_port) | + | if 'PYWEBD_PORT' in os.environ: |
+ | pywebd_port = os.environ.get('PYWEBD_PORT') | ||
+ | else: | ||
+ | pywebd_port = config['default']['Listen'] | ||
+ | if 'PYWEBD_DOC_ROOT' in os.environ: | ||
+ | pywebd_doc_root = os.environ.get('PYWEBD_DOC_ROOT') | ||
+ | else: | ||
+ | pywebd_doc_root = config['default']['DocumentRoot'] | ||
+ | |||
+ | app.run(host="0.0.0.0", port=pywebd_port, debug=True) | ||
+ | # app.run(ssl_context=('/etc/pywebd/pywebd.crt', '/etc/pywebd/pywebd.key'), debug=True, host='0.0.0.0', port=pywebd_port) | ||
</code><code> | </code><code> | ||
+ | # mkdir -p /etc/pywebd/ | ||
+ | |||
# cat /etc/pywebd/pywebd.conf | # cat /etc/pywebd/pywebd.conf | ||
</code><code> | </code><code> | ||
[default] | [default] | ||
DocumentRoot = /var/www/ | DocumentRoot = /var/www/ | ||
- | Listen = 8443 | + | Listen = 4080 |
</code><code> | </code><code> | ||
+ | # #cp /root/wild.crt /etc/pywebd/pywebd.crt | ||
+ | # #cp /root/wild.key /etc/pywebd/pywebd.key | ||
+ | </code> | ||
+ | |||
+ | * [[Средства программирования shell#Ресурсы Web сервера на shell]] | ||
+ | |||
+ | <code> | ||
(venv1) :~/pywebd$ #export PYWEBD_PORT=4443 | (venv1) :~/pywebd$ #export PYWEBD_PORT=4443 | ||
(venv1) :~/pywebd$ #export PYWEBD_DOC_ROOT=/var/www/html/ | (venv1) :~/pywebd$ #export PYWEBD_DOC_ROOT=/var/www/html/ | ||
+ | (venv1) :~/pywebd$ #PYWEBD_PORT=4443 PYWEBD_DOC_ROOT=/var/www/html/ python app.py | ||
(venv1) :~/pywebd$ python app.py | (venv1) :~/pywebd$ python app.py | ||
- | (venv1) :~/pywebd$ pip freeze > requirements.txt | + | (venv1) :~/pywebd$ pip freeze | tee requirements.txt |
</code> | </code> | ||