1.Django

1.1.Linux部署

1.1.1.使用作业部署

创建作业

screen -S name

进入作业

screen -r name

挂起作业

ctrl+a+d (先a后d)

查看作业

screen -ls

删除作业

screen  -X -S name quit

1.1.2.使用uwsgi代理启动

pip install uwsgi

在项目同名文件夹下创建 uwsgi.ini

[uwsgi]
;端口
http=0.0.0.0:8000
;项目路径
chdir=/home/1254970/项目文件夹
;wsgi.py文件路径
wsgi-file=项目同名文件夹/wsgi.py
process=4
threads=2
pidfile=uwsgi.pid
daemonize=uwsgi.log
master=True
;静态资源路径
static-map = /static=/home/1254970/项目文件夹/static

启动方式和操作方法,都是进入到项目同名文件夹下操作

查看

ps aux|grep 'uwsgi'

打开

uwsgi --ini uwsgi.ini

关闭

uwsgi --stop uwsgi.pid 关闭

注意每次操作一定要用指令查看操作是否生效,后端代码更新一定要重启服务

1.2.Windows部署

下载Apache或使用集成器

使用指令进入到python的Scripts文件夹下,运行如下代码:

mod_wsgi-express module-config

进入Apache文件夹下

在conf文件夹中创建 httpd_MyOwnProject.conf

#mod_wsgi设置(上述步骤中获取)
LoadFile "D:/Python文件/编程环境/python39.dll"
LoadModule wsgi_module "D:/Python文件/编程环境/lib/site-packages/mod_wsgi/server/mod_wsgi.cp39-win_amd64.pyd"
WSGIPythonHome "D:/Python文件/编程环境"
 
#指定website的wsgi.py配置文件路径 
WSGIScriptAlias / D:/Python文件/Django_web_file/yibao/yibao/wsgi.py
​
 
#指定项目路径  
WSGIPythonPath  D:/Python文件/Django_web_file/yibao
<Directory D:/Python文件/Django_web_file/yibao/yibao>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
 
# 项目静态文件地址, Django项目中静态文件的路径  
Alias /static D:\Python文件\Django_web_file\yibao\static
<Directory D:\Python文件\Django_web_file\yibao\static>
AllowOverride None
Options None
Require all granted
</Directory>
 
# #项目media地址, 上传图片等文件夹的路径
Alias /media D:\Python文件\Django_web_file\yibao\media
<Directory D:\Python文件\Django_web_file\yibao\media>
AllowOverride None
Options None
Require all granted
</Directory>

httpd.conf文件末尾添加

Include conf/httpd_MyOwnProject.conf

1.3.Windows部署 (2) daphne代理

settings.py中添加

# ASGI启动配置
ASGI_APPLICATION = 'OnEd.asgi.application'

安装 daphne

pip install daphne

启动项目

daphne -b 0.0.0.0 -p 8220 XXX.asgi:application

端口自取,XXX为项目名称,settings.py所在的文件夹名称

nginx 配置的主要内容

   upstream django {
        server 127.0.0.1:8220;  # Daphne 或 Waitress 服务地址和端口
    }
    server {
        listen 8200;
        location / {
            proxy_pass http://django;
            # proxy_set_header Host $host;
            proxy_set_header Host $http_host;  
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
        location /media {
           alias D:/media;   # 指定静态文件的实际路径
        }
         location /static {
           alias D:/static;   # 指定静态文件的实际路径
        }
    }

2.Springboot

2.1.运行项目

idea或者 eclipse中将java程序打包成jar包

1.linux系统

使用作业运行项目,参考linux作业

进入到jar所在的文件夹内,运行指令如下(xxxx为jar包名):

java -jar xxxx.jar

2.win系统

直接 ctrl+win,输入 cmd ,运行同上

2.2.Nginx操作

下载

apt-get install nginx

修改Nginx安装目录下的conf/nginx.conf

cd /etc/nginx

#user  nobody;
worker_processes  1;
​
#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;
​
#pid        logs/nginx.pid;
​
​
events {
    worker_connections  10240;
}
​
​
http {
    include       mime.types;
    default_type  application/octet-stream;
​
    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';
​
    #access_log  logs/access.log  main;
​
    sendfile        on;
    #tcp_nopush     on;
​
    #keepalive_timeout  0;
    keepalive_timeout  65;
​
    #gzip  on;
​
   
    server {
    listen       80;
    server_name  IP;
    access_log /var/log/nginx/user.log;
    error_log /var/log/nginx/user.error;
​
    #location后是路由,转发到proxy_pass后的网址
    location / {
   
        proxy_pass http://IP:0000;
    }
     #可以有多个转发
    location /dome {
             #dome可以不一样,但是...最好一样
        proxy_pass http://IP:0000/dome1;
    }
 
​
}
   
}
​
​
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
#    serve

启动nginx服务:

sudo systemctl start nginx

停止nginx服务:

sudo systemctl stop nginx

重启nginx服务:

sudo systemctl restart nginx

重新加载nginx配置文件:

sudo systemctl reload nginx

查看nginx状态:

sudo systemctl status nginx