xshell项目部署

1:下载xshell,连接远程的阿里服务器

在这里插入图片描述

2:连接成功后要部署自己的环境

Ubuntu安装python 3. 7: 1:https://www.cnblogs.com/pengmn/p/12905723.html
安装mysql 2:http://www.mamicode.com/info-detail-2182600.html
安装虚拟环境 3:https://blog.csdn.net/qq_41621362/article/details/89606522

3:创建一个文件夹 mkdir 文件夹名

4:将vue打包npm run build打包后的dist文件移到自己的服务器上面,转移文件的时候可以使用 Xftp7

在这里插入图片描述

5:将自己的django全部项目也转移到刚刚所创的文件夹下面(记得删除项目里迁移生成的文件,要将setting的DEBUG = True 改成DEBUG = False)

6:进入虚拟环境,将Python的环境都安装到虚拟环境内

7:安装uwsgi和配置uwsgi

’’‘1. 安装uwsgi’’'
pip3 install uwsgi # 安装uwsgi
whereis uwsgi # 查看uwsgi安装路径

2:配置uwgsi.ini启动文件
在上面创建的文件夹下面新建一个mkdir uwsgi_conf
进入cd uwsgi_conf在创建一个vim uwsgi.ini 文件
在uwsgi.ini里面写入:
[uwsgi]
#使用Nginx连接时使用,Django程序所在服务器地址和端口号
socket=127.0.0.1:8000
#项目目录绝对路径
chdir=/teach/shiyanlou_project/syl
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=syl/wsgi.py
#进程数(机器核数的1倍)
processes=4
#线程数
threads=50
#uwsgi服务器的角色
master=True
#存放进程编号的文件
pidfile=uwsgi.pid
#日志文件
daemonize=uwsgi.log
#指定依赖的虚拟环境
virtualenv=/root/.virtualenvs/syl
在这里插入图片描述

8: 使用uwsgi启动django:一定要在这个项目目录中

使用uwsgi启动django:一定要在这个项目目录中’
uwsgi --http 192.168.56.100:6666 --file syl/wsgi.py --static-map=/static=static
访问项目:http://192.168.56.11

9:安装配置nginx

sudo apt update # 更新apt
sudo apt install nginx # 安装nginx
sudo systemctl status nginx # 查看nginx状态

10:配置nginx+uwsgi起的

/etc/nginx/conf.d/文件夹下新建任意名字 xxx.conf即可,写入的内容是官方给的

#/etc/nginx/conf.d/django.conf
server {
listen 8888;
server_name 192.168.56.100;
# /teach/shiyanlou_project/syl/static/admin/css/base.css
# http://192.168.56.100/static/admin/css/base.css
location /static {
alias /teach/shiyanlou_project/syl/static;
}

    location / {
          include uwsgi_params;
          uwsgi_pass 127.0.0.1:8000;
          uwsgi_ignore_client_abort on;
    }

}

11:/etc/nginx/nginx.confnginx主配置文件解读(不用变)

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
worker_connections 768; # 链接数量
}

http {
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;

access_log /var/log/nginx/access.log;         # 1.客户浏览器访问nginx服务记录(客户户端访问异常时可以查看)
error_log /var/log/nginx/error.log;           # 2.nginx错误日志(nginx启动时报错的日志)
include /etc/nginx/conf.d/*.conf;             # 3.nginx扩展配置文件
include /etc/nginx/sites-enabled/*;

}

12:uwsgi和nginx 启动、关闭、查看日志

‘’‘1.启动并查看nginx日志’’’
[root@linux-node1 demo2]# systemctl restart nginx # 开启nginx
root@dev:uwsgi_conf# tail -f /var/log/nginx/access.log # 查看nginx接入日志
root@dev:uwsgi_conf# tail -f /var/log/nginx/error.log # 查看nginx错误日志

‘’‘2.启动并查看uwsgi日志’’’
root@dev:uwsgi_conf# cd /teach/shiyanlou_project/uwsgi_conf # 进入实验楼目录
[root@linux-node1 demo2]# uwsgi --ini uwsgi.ini # 启动uwsgi的django项目
#http://192.168.56.100:8888/ 访问项目
[root@linux-node1 demo2]# uwsgi --stop uwsgi.pid # 关闭uwsgi
[root@dev:uwsgi_conf# tail -f uwsgi.log # 查看uwsgi日志

(syl) root@dev:uwsgi_conf# ps -ef|grep uwsgi # 查看uwsgi服务是否启动
root 92328 89266 0 14:37 pts/1 00:00:00 grep --color=auto uwsgi
(syl) root@dev:uwsgi_conf# netstat -anptu | grep 8888 # 查看8888端口被哪一个程序占用

nginx和uwsgi最后的样子

nginx:
server {
listen 8000;
server_name 172.16.240.177;
# /teach/shiyanlou_project/syl/static/admin/css/base.css
# http://192.168.56.100/static/admin/css/base.css
location /static {
alias /teach/shiyanlou_project/syl/static;
}

    location / {
          include uwsgi_params;
          uwsgi_pass 127.0.0.1:3031;
          uwsgi_ignore_client_abort on;
    }

}
server {
listen 8080; #1.你想让你的这个项目跑在哪个端口
server_name 172.16.240.177; #2.当前服务器ip
location / {
root /home/peter/syl_program/dist; #3.dist文件的位置(我是直接放在home目录下了)
try_files $uri $uri/ /index.html; #4.重定向,内部文件的指向(照写)
}
}

uwsgi:

[uwsgi]
#使用Nginx连接时使用,Django程序所在服务器地址和端口号
socket=127.0.0.1:3031
#http=172.16.240.177:8000
#项目目录绝对路径
chdir=/home/peter/syl_program/code2001B
#项目中wsgi.py文件的目录,相对于项目目录
wsgi-file=code2001B/wsgi.py
#进程数(机器核数的1倍)
processes=4
#线程数
threads=50
#uwsgi服务器的角色
master=True
#存放进程编号的文件
pidfile=uwsgi.pid
#日志文件
daemonize=uwsgi.log
#指定依赖的虚拟环境
#virtualenv=/root/.virtualenvs/syl

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值