前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >04.Python Dash网页开发:ubuntu服务器部署DASH网站(uWSGI+nginx)

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

原创
作者头像
生信探索
发布2023-05-23 09:01:18
6740
发布2023-05-23 09:01:18
举报
文章被收录于专栏:生信探索生信探索

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

Python enviroment

代码语言:Python
复制
mkdir bioquest
vi ~/bioquest/dash.yaml
micromamba env create -n dash --file dash.yaml
micromamba activate dash
代码语言:YAML
复制
# 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

代码语言:Python
复制
server = app.server

Create wsgi.py

代码语言:Python
复制
# vi ~/bioquest/wsgi.py
from app import server as application
if __name__ == '__main__':
    application.run()

Create index.ini

代码语言:Python
复制
# 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

代码语言:Python
复制
# 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

代码语言:Python
复制
sudo systemctl restart index.service
sudo systemctl status index.service

现在的~/bioquest文件夹

代码语言:YAML
复制
app.py  
index.ini  
index.sock  
pages  
__pycache__  
static  
wsgi.py
dash.yaml

Configure Nginx

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

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

代码语言:shell
复制
sudo apt install nginx
sudo vi /etc/nginx/sites-available/default
代码语言:shell
复制
server {
    listen 1314;
    server_name 111.230.57.251;
    location / {
            include uwsgi_params; 
            uwsgi_pass unix:/home/ubuntu/bioquest/index.sock;          
     }
}

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

代码语言:YAML
复制
sudo vi /etc/nginx/nginx.conf
代码语言:shell
复制
user root;

启动所有服务

代码语言:shell
复制
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

代码语言:Python
复制
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

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Python enviroment
  • directory
  • Create wsgi.py
  • Create index.ini
  • Create index.service
  • Configure Nginx
  • 启动所有服务
  • References
相关产品与服务
云服务器
云服务器(Cloud Virtual Machine,CVM)提供安全可靠的弹性计算服务。 您可以实时扩展或缩减计算资源,适应变化的业务需求,并只需按实际使用的资源计费。使用 CVM 可以极大降低您的软硬件采购成本,简化 IT 运维工作。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档