UbuntuServer1804设置uwsgi自启动服务
在 Ubuntu 上使用 Nginx+ uWSGI 部署Django项目,在实际生成环境中需要系统自动启动这两项服务,Ubuntu默认自启动Nginx,需要对uwsgi设置为系统自启动。
Ubuntu1804采用systemctl来管理开机启动的脚本,对于uwsgi服务要设置成系统服务来进行自启动。
1、首先创建 uwsgi.service
文件
目录位置:/etc/systemd/system/
sudo vim /etc/systemd/system/uwsgi.service
[Unit]
Description=uWSGI server
After=syslog.target
[Service]
#用户名
User=user_name
#项目目录
WorkingDirectory=/home/username/projectname
#需要的环境变量配置文件
#Environment=/home/username/projectname/env.cfg
#服务启动的代码,可用which命令查看uwsgi的具体位置User=username
ExecStart=/home/username/.local/bin/uwsgi --ini uwsgi.ini
#用户组
Group=www-data
[Install]
#指明会跟随系统启动而启动该服务
WantedBy=multi-user.target
2、启动、停止、重启、查看服务命令 :
sudo systemctl start uwsgi.service
sudo systemctl stop uwsgi.service
sudo systemctl restart uwsgi.service
sudo systemctl status uwsgi.service #查看服务状态,可查看错误信息
3、加入、关闭系统自启动:
sudo systemctl daemon-reload
sudo systemctl enable uwsgi.service
sudo systemctl disable uwsgi.service
执行此命令后在/etc/systemd/system/multi-user.target.wants目录下生成uwsgi.sevice的链接文件,
Ubuntu1804系统的自启动项目均在此目录下。重启系统后,可看到uwsgi服务已启动。
4、总结:
1、建立service文件,必须保证文件编辑正确,因为不返回执行结果;注意注释格式(最好去掉),建议使用vi编辑,有的编辑器会带有空格;
2、建立链接文件或复制文件到/etc/systemd/system/目录中;
3、通过systemctl enable uwsgi.service命令在/etc/systemd/system/multi-user.target.wants目录下生成uwsgi.sevice的链接文件。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!