- 理解代理关系
- 角色
- Nginx 反向代理服务器,负责分发静态文件,Django仍然处理逻辑;
- 角色
- 操作步骤
1. create directory
cd /
mkdir s25luffy
cd s25luffy
2. obtain vue source code
wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip
3. unzip file and compile vue
unzip 07-luffy_project_01.zip
rm -rf 07-luffy_project_01.zip
rm -rf __MACOSX/
configuration Node.js environment
wget https://npm.taobao.org/mirrors/node/v16.13.0/node-v16.13.0-linux-x64.tar.xz
xz -d node-v16.13.0-linux-x64.tar.xz
tar -xvf node-v16.13.0-linux-x64.tar
rm -rf node-v16.13.0-linux-x64.tar
add environment variable
vim /etc/profile
PATH="/opt/tengine233/sbin:/opt/python396/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin:/s25luffy/node-v16.13.0-linux-x64/bin"
refresh environment variable
source /etc/profile
check version
node -v
npm -v
change ip in vue_program/src
1. change dir
/s25luffy/07-luffy_project_01/src/restful
2. edit file
vim api.js
qiut vim and execute command
cd /s25luffy/07-luffy_project_01/src/restful
sed -i 's/127.0.0.1:8000/192.168.1.9:9000/g' api.js
configuration dependency file
cd /s25luffy/07-luffy_project_01
change source
npm config set registry https://registry.npm.taobao.org
npm install -g npm@8.1.3
npm install # 2m
notice
npm notice New patch version of npm available! 8.1.0 -> 8.1.3
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.1.3
npm notice Run npm install -g npm@8.1.3 to update!
npm run build
4. configuration nginx.conf
5. refresh nginx configuration
nginx -t
nginx -s reload
Problems
losing of static file
deployment of rear end
tips
1. configuration file
cd s25luffy/
wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip
unzip luffy_boy.zip
rm -rf luffy_boy.zip
rm -rf __MACOSX/
2. check IP white list
vim luffy_boy/luffy_boy/settings.py
3. configuration of virtualenv
python3 -m venv luffyboy_env
source luffyboy_env/bin/activate
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
cd luffy_boy/
vim requirements.txt
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple wheel
deactivate /luffyboy_env/bin
4. test django program
source /s25luffy/luffyboy_env/bin/activate
cd /s25luffy/luffy_boy
python3 manage.py runserver 0.0.0.0:4495
5. configurate uwsgi
cd /s25luffy/luffy_boy
vim uwsgi.ini
vim vim /opt/tengine233/conf/nginx.conf
6. test uwsgi
cd /s25luffy/luffy_boy
uwsgi --ini /etc/uwsgi_nginx.ini
7. configuration supervisor
vim /etc/supervisord.conf
ps -ef | grep supervisor # 检查supervisor 进程是否在运行
supervisord -c /etc/supervisord.conf # 启动
> status # 查看项目状态
8. Nginx cf 9005 port
netstat -tunlp # 查看端口占用情况
#这一条参数确保vue页面刷新时候,不会出现404页面
try_files $uri $uri/ /index. html;
uwsgi_ pass
0.0.0.0:9005;
include uwsgi_ params ;
}
}
9. 登录luffy网站
account : alex
password: alex3714
10. 购物车依赖redis, 因此安装redis
yum -y install redis
systemctl start redis
uwsgi配置
[uwsgi]
# Django-related settings
uid = www
gid = www
# 填写CRM项目第一层绝对路径
chdir = /s25luffy/luffy_boy
# 填写 CRM 项目第二层相对路径,找到第二层目录下的wsgi.py
# 这里写的不是路径,而是以上一个参数为相对,找到第二层目录下的wsgi.py文件
module = luffy_boy.wsgi
# 虚拟环境Python解释器路径
home = /s25luffy/luffyboy_env
# process-related settings
# master
master = true
# 推荐性能为 核数 * 2 + 1
processes = 3
#threads = 2
# socket和Nginx结合部署 unix-socket参数,这里先临时暂停使用
# the socket (use the full path to be safe
# socket = 192.168.1.9:20001
# 线上部署不会使用http参数,对于后端不安全,使用socket连结是安全的,用Nginx反向代理去访问
# 后端程序是运行在防火墙内部,外网无法直接访问
# 临时使用http参数,便于浏览器直接调试
# http = 0.0.0.0:10001
# ... with appropriate permissions - may be needed
# chmod-socket = 664
# clear environment on exit
vacuum = true
pidfile=uwsgi.pid
daemon=uwsgi.log
Nginx configuration
Supervisor
[program:Luffyvue]
command=/s25luffy/luffyboy_env/bin/uwsgi --ini /s25luffy/luffy_boy/uwsgi.ini
autostart=true ; 在supervisord启动的时候也自动启动
startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1秒
autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
startretries=3 ; 启动失败自动重试次数,默认是3
stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
stdout_logfile=/tmp/luffyvue.out ; 需要用户新建该目录
其他
安装vscodiumcommand
sudo tee -a /etc/yum.repos.d/vscodium.repo << 'EOF'
[gitlab.com_paulcarroty_vscodium_repo]
name=gitlab.com_paulcarroty_vscodium_repo
baseurl=https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/rpms/
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg
metadata_expire=1h
EOF
yum -y update
yum -y install vscodium
link ```markdown
- install codium https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo
install Sublime Text3 https://www.sublimetext.com/docs/linux_repositories.html#yum ```
- 备注
- 127.0.0.1 是本地回环地址,部署到服务器时应该修改这部分访问路径;
- 替换命令的解释 s是替换命令 /替换前的内容/替换后的内容/ g=global 全局替换
- 全局替换npm source https://www.cnblogs.com/cythia/p/10985080.html
- backup of nginx configuration
- 备注
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#error_log "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
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;
#access_log "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G" main;
#log_format caesar_01 '[$time_local] $remote_addr "$request" $status'
log_format main_json '{"@timestamp":"$time_iso8601",'
'"@version":"1",'
'"server_addr":"$server_addr",'
'"remote_addr":"$remote_addr",'
'"host":"$host",'
'"uri":"$uri",'
'"body_bytes_sent":$body_bytes_sent,'
'"bytes_sent":$body_bytes_sent,'
'"upstream_response_time":$upstream_response_time,'
'"request":"$request",'
'"request_length":$request_length,'
'"request_time":$request_time,'
'"status":"$status",'
'"http_referer":"$http_referer",'
'"http_x_forwarded_for":"$http_x_forwarded_for",'
'"http_user_agent":"$http_user_agent"'
'}';
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
charset utf-8;
access_log logs/host.access.log main_json;
#access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
location / {
root html;
index index.html index.htm;
}
# /opt/tengine233/html/a/html
location /a {
allow 127.0.0.1;
deny all;
}
location /b {
auth_basic "登陆验证";
auth_basic_user_file /etc/nginx/htpasswd;
}
error_page 404 /404.html;
#redirect server error pages to the static page /50x.html
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 81;
server_name localhost;
charset utf-8;
location / {
root /s25luffy/07-luffy_project_01/dist;
index index.html;
}
}
}