打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
04.Python Dash网页开发:ubuntu服务器部署DASH网站(uWSGI+nginx)

Dash官网只有付费的部署方式❌
我的简单理解,uWSGI去运行dash app并且与nginx通讯;nginx处理浏览器传来的请求并把需求给uWSGI

Python enviroment

mkdir bioquest
vi ~/bioquest/dash.yaml
micromamba env create -n dash --file dash.yaml
micromamba activate dash

# vi ~/bioquest/dash.yaml
channels:
 - conda-forge
dependencies:
 - python=3.10
 - dash-bootstrap-components
 - numpy
 - pandas
 - plotly
 - dash-bootstrap-templates
 - scikit-learn
 - matplotlib
 - seaborn
 - uwsgi

directory

app还是上个推文的 03.Python Dash网页开发:多页面网站制作

把app全部文件目录复制到~/bioquest文件夹下

并且需要再app.py文件最后一行加上,因为wsgi从app.py中导入并运行的是server

server = app.server

Create wsgi.py

# vi ~/bioquest/wsgi.py
from app import server as application
if __name__ == '__main__':
    application.run()

Create index.ini

# vi ~/bioquest/index.ini
[uwsgi]
module = wsgi
master = true
processes = 2
socket = index.scok
chmod-socket = 770
vacuum = true
die-on-term = true
py-autoreload = 1

Create index.service

# sudo vi /etc/systemd/system/index.service
[Unit]
Description=uWSGI instance to serve index
After=network.target
[Service]
User=ubuntu
Group=www-data
WorkingDirectory=/home/ubuntu/bioquest
ExecStart=/home/ubuntu/micromamba/envs/dash/bin/uwsgi --force-cwd /home/ubuntu/bioquest --ini index.ini
StandardError=syslog
[Install]
WantedBy = multi-user.target

start and check

sudo systemctl restart index.service
sudo systemctl status index.service

现在的~/bioquest文件夹

app.py  
index.ini  
index.sock  
pages  
__pycache__  
static  
wsgi.py
dash.yaml

Configure Nginx

修改Nginx默认配置文件default。腾讯云服务器绑定域名需要备案,比较麻烦,所以暂时还是不搞吧。

需要在腾讯云服务器开一个新端口1314,如果用80或433应该就不需要新开端口了,因为一般都会默认开通。

sudo apt install nginx
sudo vi /etc/nginx/sites-available/default

server {
    listen 1314;
    server_name 111.230.57.251;
    location / {
            include uwsgi_params; 
            uwsgi_pass unix:/home/ubuntu/bioquest/index.sock;          
     }
}

修改Nginx配置,把user改为启动用户即root

sudo vi /etc/nginx/nginx.conf
user root;

启动所有服务

sudo systemctl daemon-reload
sudo systemctl start index.service
sudo systemctl enable index
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status index
sudo service nginx restart

#访问和错误日志
#/var/log/nginx/access.log
#/var/log/nginx/error.log

现在就可以在浏览器中访问到DASH网站了http://111.230.57.251:1314/

References

https://carpiero.medium.com/host-a-dashboard-using-python-dash-and-linux-in-your-own-linux-server-85d891e960bc
https://medium.com/swlh/create-your-own-linux-server-with-nginx-for-beginners-with-ip-public-40c6c004b0b4
https://towardsdatascience.com/how-to-create-your-first-web-app-using-python-plotly-dash-and-google-sheets-api-7a2fe3f5d256

# nginx
https://www.nginx.com/resources/wiki/start/
https://www.nginx.com/resources/wiki/start/topics/tutorials/config_pitfalls/
https://wiki.debian.org/Nginx/DirectoryStructure
https://blog.csdn.net/u011262253/article/details/120941175
https://www.runoob.com/w3cnote/nginx-setup-intro.html
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Flask + Gunicorn + Nginx 部署 - Ray Liang - 博客园
Linux - CentOS 7 通过Yum源安装 Nginx
Nginx+uwsgi跑Django应用 2011-06-22 19:51:59
ubuntu server 12.04LTS+Nginx+uWSGI+web.py 配置备忘
大牛分享|如何用Django Uwsgi Nginx 实现生产环境部署
Django在Ubuntu14.04的部署
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服