{"id":17647079,"url":"https://github.com/yuehhua/deploy-flask","last_synced_at":"2025-10-12T23:07:09.130Z","repository":{"id":87446387,"uuid":"188517095","full_name":"yuehhua/deploy-flask","owner":"yuehhua","description":"A demo of deployment of flask, uwsgi and nginx stack.","archived":false,"fork":false,"pushed_at":"2019-05-29T03:42:11.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-07-11T14:42:24.156Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuehhua.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-25T03:44:01.000Z","updated_at":"2019-05-29T03:42:13.000Z","dependencies_parsed_at":"2023-12-01T03:31:23.241Z","dependency_job_id":null,"html_url":"https://github.com/yuehhua/deploy-flask","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yuehhua/deploy-flask","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuehhua%2Fdeploy-flask","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuehhua%2Fdeploy-flask/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuehhua%2Fdeploy-flask/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuehhua%2Fdeploy-flask/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuehhua","download_url":"https://codeload.github.com/yuehhua/deploy-flask/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuehhua%2Fdeploy-flask/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279013456,"owners_count":26085274,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-12T02:00:06.719Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-23T11:10:09.910Z","updated_at":"2025-10-12T23:07:09.083Z","avatar_url":"https://github.com/yuehhua.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# deploy-flask\nA demo of deployment of flask, uwsgi and nginx stack.\n\n## STEP 1: write a simple flask app\n\n* Establish a virtualenv `virtualenv venv -p python3`\n* Activate environment: `. venv/bin/activate`\n* `pip install -r requirements.txt`\n* Write a simple flask app `hello.py`\n* Run `python hello.py`\n* Test http://127.0.0.1:5000/ on browser\n\n## STEP 2: host the flask app with uwsgi\n\n* Configure with `uwsgi.ini`\n* Run `uwsgi --ini uwsgi.ini`\n* Test http://127.0.0.1:8080/ on browser\n\nYou will see some log in `demo.log`:\n\n```\n*** Starting uWSGI 2.0.18 (64bit) on [Sat May 25 11:56:26 2019] ***\ncompiled with version: 8.2.1 20181127 on 10 February 2019 15:11:33\nos: Linux-5.1.3-arch2-1-ARCH #1 SMP PREEMPT Tue May 21 23:16:12 UTC 2019\nnodename: antergos-K55VJ\nmachine: x86_64\nclock source: unix\npcre jit disabled\ndetected number of CPU cores: 4\ncurrent working directory: /media/pika/Workbench/workspace/deploy-flask\ndetected binary path: /usr/bin/uwsgi\nchdir() to .\nyour processes number limit is 63396\nyour memory page size is 4096 bytes\ndetected max file descriptor number: 1024\nlock engine: pthread robust mutexes\nthunder lock: enabled\nuWSGI http bound on 127.0.0.1:8080 fd 3\nuwsgi socket 0 bound to UNIX address /tmp/demo.sock fd 6\nPython version: 3.7.3 (default, Mar 26 2019, 21:43:19)  [GCC 8.2.1 20181127]\nSet PythonHome to venv\nPython main interpreter initialized at 0x55761c31c2d0\npython threads support enabled\nyour server socket listen backlog is limited to 100 connections\nyour mercy for graceful operations on workers is 60 seconds\nmapped 291680 bytes (284 KB) for 3 cores\n*** Operational MODE: preforking ***\nWSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x55761c31c2d0 pid: 21349 (default app)\n*** uWSGI is running in multiple interpreter mode ***\nspawned uWSGI master process (pid: 21349)\nspawned uWSGI worker 1 (pid: 21351, cores: 1)\nspawned uWSGI worker 2 (pid: 21352, cores: 1)\nspawned uWSGI worker 3 (pid: 21353, cores: 1)\nspawned uWSGI http 1 (pid: 21354)\n[pid: 21351|app: 0|req: 1/1] 127.0.0.1 () {36 vars in 669 bytes} [Sat May 25 11:56:36 2019] GET / =\u003e generated 12 bytes in 2 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)\nSIGINT/SIGQUIT received...killing workers...\ngateway \"uWSGI http 1\" has been buried (pid: 21354)\nworker 1 buried after 1 seconds\nworker 2 buried after 1 seconds\nworker 3 buried after 1 seconds\ngoodbye to uWSGI.\nVACUUM: unix socket /tmp/demo.sock removed.\n```\n\n## STEP 3: setup service with systemd for your project\n\n* Place `uwsgi.ini` to `/etc/uwsgi/vassals/uwsgi.ini`\n* Create and configure service `/etc/systemd/system/demo.service`\n* Start service with `sudo systemctl start demo.service`, and it would run `uwsgi --ini uwsgi.ini` as a service for you\n\n* Check service status with `sudo systemctl status demo.service`\n* Stop service with `sudo systemctl stop demo.service`\n\n## STEP 4: set web server with nginx\n\n* Update repo with `sudo apt update`\n* Install nginx in your OS: `sudo apt install nginx`\n* Configure with `demo.conf`\n    * Change `server_name` to YOUR-IP or 127.0.0.1\n* Create configure file link to nginx: `sudo ln -s /your/path/to/demo/demo.conf /etc/nginx/sites-available/demo.conf`\n    * In Ubuntu, place conf in `/etc/nginx/sites-available/` and link to `/etc/nginx/sites-enabled/`\n    * In CentOS, place conf in `/etc/nginx/conf.d/`\n* Start nginx service with `sudo systemctl start nginx.service`\n* Test http://YOUR-IP/ on browser\n\nYou will see some log in `demo.log`:\n\n```\n*** Starting uWSGI 2.0.18 (64bit) on [Sat May 25 11:33:07 2019] ***\ncompiled with version: 8.2.1 20181127 on 10 February 2019 15:11:33\nos: Linux-5.1.3-arch2-1-ARCH #1 SMP PREEMPT Tue May 21 23:16:12 UTC 2019\nnodename: antergos-K55VJ\nmachine: x86_64\nclock source: unix\npcre jit disabled\ndetected number of CPU cores: 4\ncurrent working directory: /home/pika/demo\ndetected binary path: /usr/bin/uwsgi\nchdir() to /home/pika/demo\nyour processes number limit is 63396\nyour memory page size is 4096 bytes\ndetected max file descriptor number: 1024\nlock engine: pthread robust mutexes\nthunder lock: enabled\nuWSGI http bound on 127.0.0.1:8080 fd 3\nuwsgi socket 0 bound to UNIX address /tmp/demo.sock fd 6\nPython version: 3.7.3 (default, Mar 26 2019, 21:43:19)  [GCC 8.2.1 20181127]\nSet PythonHome to /home/pika/demo/venv\nPython main interpreter initialized at 0x56511f40ba00\npython threads support enabled\nyour server socket listen backlog is limited to 100 connections\nyour mercy for graceful operations on workers is 60 seconds\nmapped 291680 bytes (284 KB) for 3 cores\n*** Operational MODE: preforking ***\nWSGI app 0 (mountpoint='') ready in 0 seconds on interpreter 0x56511f40ba00 pid: 17701 (default app)\n*** uWSGI is running in multiple interpreter mode ***\nspawned uWSGI master process (pid: 17701)\nspawned uWSGI worker 1 (pid: 17702, cores: 1)\nspawned uWSGI worker 2 (pid: 17703, cores: 1)\nspawned uWSGI worker 3 (pid: 17704, cores: 1)\nspawned uWSGI http 1 (pid: 17705)\n[pid: 17702|app: 0|req: 1/1] 192.168.100.102 () {46 vars in 846 bytes} [Sat May 25 11:33:15 2019] GET / =\u003e generated 12 bytes in 3 msecs (HTTP/1.1 200) 2 headers in 79 bytes (1 switches on core 0)\nSIGINT/SIGQUIT received...killing workers...\ngateway \"uWSGI http 1\" has been buried (pid: 17705)\nworker 1 buried after 1 seconds\nworker 2 buried after 1 seconds\nworker 3 buried after 1 seconds\ngoodbye to uWSGI.\nVACUUM: unix socket /tmp/demo.sock removed.\n```\n\n* Check service status with `sudo systemctl status nginx.service`\n* Stop service with `sudo systemctl stop nginx.service`\n* Reload config without stoping a service with `sudo systemctl reload nginx.service`\n\n## STEP 5: serve static files with nginx\n\n* Create the directory for your static files, usually we place under `/var/www/demo`\n* Place your static files under `/var/www/demo`\n* Configure `demo.conf` with `root` for directing the static files directory and `index` for your home pages.\n* [try_files docs](https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/#trying-several-options)\n* Setup privileges of static files and folders with owner **www-data** and mode **755**\n\n```\nserver {\n  listen 80;\n  server_name 127.0.0.1;\n  \n  root /var/www/demo;\n  index index.html;\n\n  location / {\n    try_files $uri $uri/ =404;\n  }\n\n  location /static/ {\n    alias /var/www/demo/static/;\n  }\n}\n```\n\n## Further reading\n\n[使用 uWSGI、nginx、systemd 部署 Django](https://blog.liang2.tw/posts/2016/05/django-deploy-uwsgi-nginx-systemd/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuehhua%2Fdeploy-flask","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuehhua%2Fdeploy-flask","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuehhua%2Fdeploy-flask/lists"}