1. 理解代理关系
    1. 角色
      1. Nginx 反向代理服务器,负责分发静态文件,Django仍然处理逻辑;
  2. 操作步骤
  1. 1. create directory
  2. cd /
  3. mkdir s25luffy
  4. cd s25luffy
  5. 2. obtain vue source code
  6. wget https://files.cnblogs.com/files/pyyu/07-luffy_project_01.zip
  7. 3. unzip file and compile vue
  8. unzip 07-luffy_project_01.zip
  9. rm -rf 07-luffy_project_01.zip
  10. rm -rf __MACOSX/
  11. configuration Node.js environment
  12. wget https://npm.taobao.org/mirrors/node/v16.13.0/node-v16.13.0-linux-x64.tar.xz
  13. xz -d node-v16.13.0-linux-x64.tar.xz
  14. tar -xvf node-v16.13.0-linux-x64.tar
  15. rm -rf node-v16.13.0-linux-x64.tar
  16. add environment variable
  17. vim /etc/profile
  18. 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"
  19. refresh environment variable
  20. source /etc/profile
  21. check version
  22. node -v
  23. npm -v
  24. change ip in vue_program/src
  25. 1. change dir
  26. /s25luffy/07-luffy_project_01/src/restful
  27. 2. edit file
  28. vim api.js
  29. qiut vim and execute command
  30. cd /s25luffy/07-luffy_project_01/src/restful
  31. sed -i 's/127.0.0.1:8000/192.168.1.9:9000/g' api.js
  32. configuration dependency file
  33. cd /s25luffy/07-luffy_project_01
  34. change source
  35. npm config set registry https://registry.npm.taobao.org
  36. npm install -g npm@8.1.3
  37. npm install # 2m
  38. notice
  39. npm notice New patch version of npm available! 8.1.0 -> 8.1.3
  40. npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.1.3
  41. npm notice Run npm install -g npm@8.1.3 to update!
  42. npm run build
  43. 4. configuration nginx.conf
  44. 5. refresh nginx configuration
  45. nginx -t
  46. nginx -s reload

warning in npm run build

图片.pngProblems

losing of static file图片.png

deployment of rear end

tips

  1. 1. configuration file
  2. cd s25luffy/
  3. wget https://files.cnblogs.com/files/pyyu/luffy_boy.zip
  4. unzip luffy_boy.zip
  5. rm -rf luffy_boy.zip
  6. rm -rf __MACOSX/
  7. 2. check IP white list
  8. vim luffy_boy/luffy_boy/settings.py
  9. 3. configuration of virtualenv
  10. python3 -m venv luffyboy_env
  11. source luffyboy_env/bin/activate
  12. pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
  13. cd luffy_boy/
  14. vim requirements.txt
  15. pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
  16. pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple wheel
  17. deactivate /luffyboy_env/bin
  18. 4. test django program
  19. source /s25luffy/luffyboy_env/bin/activate
  20. cd /s25luffy/luffy_boy
  21. python3 manage.py runserver 0.0.0.0:4495
  22. 5. configurate uwsgi
  23. cd /s25luffy/luffy_boy
  24. vim uwsgi.ini
  25. vim vim /opt/tengine233/conf/nginx.conf
  26. 6. test uwsgi
  27. cd /s25luffy/luffy_boy
  28. uwsgi --ini /etc/uwsgi_nginx.ini
  29. 7. configuration supervisor
  30. vim /etc/supervisord.conf
  31. ps -ef | grep supervisor # 检查supervisor 进程是否在运行
  32. supervisord -c /etc/supervisord.conf # 启动
  33. > status # 查看项目状态
  34. 8. Nginx cf 9005 port
  35. netstat -tunlp # 查看端口占用情况
  36. #这一条参数确保vue页面刷新时候,不会出现404页面
  37. try_files $uri $uri/ /index. html;
  38. uwsgi_ pass
  39. 0.0.0.0:9005;
  40. include uwsgi_ params ;
  41. }
  42. }
  43. 9. 登录luffy网站
  44. account : alex
  45. password: alex3714
  46. 10. 购物车依赖redis 因此安装redis
  47. yum -y install redis
  48. systemctl start redis

uwsgi配置

  1. [uwsgi]
  2. # Django-related settings
  3. uid = www
  4. gid = www
  5. # 填写CRM项目第一层绝对路径
  6. chdir = /s25luffy/luffy_boy
  7. # 填写 CRM 项目第二层相对路径,找到第二层目录下的wsgi.py
  8. # 这里写的不是路径,而是以上一个参数为相对,找到第二层目录下的wsgi.py文件
  9. module = luffy_boy.wsgi
  10. # 虚拟环境Python解释器路径
  11. home = /s25luffy/luffyboy_env
  12. # process-related settings
  13. # master
  14. master = true
  15. # 推荐性能为 核数 * 2 + 1
  16. processes = 3
  17. #threads = 2
  18. # socket和Nginx结合部署 unix-socket参数,这里先临时暂停使用
  19. # the socket (use the full path to be safe
  20. # socket = 192.168.1.9:20001
  21. # 线上部署不会使用http参数,对于后端不安全,使用socket连结是安全的,用Nginx反向代理去访问
  22. # 后端程序是运行在防火墙内部,外网无法直接访问
  23. # 临时使用http参数,便于浏览器直接调试
  24. # http = 0.0.0.0:10001
  25. # ... with appropriate permissions - may be needed
  26. # chmod-socket = 664
  27. # clear environment on exit
  28. vacuum = true
  29. pidfile=uwsgi.pid
  30. daemon=uwsgi.log

Nginx configuration

Supervisor

  1. [program:Luffyvue]
  2. command=/s25luffy/luffyboy_env/bin/uwsgi --ini /s25luffy/luffy_boy/uwsgi.ini
  3. autostart=true ; supervisord启动的时候也自动启动
  4. startsecs=10 ; 启动10秒后没有异常退出,就表示进程正常启动了,默认为1
  5. autorestart=true ; 程序退出后自动重启,可选值:[unexpected,true,false],默认为unexpected,表示进程意外杀死后才重启
  6. startretries=3 ; 启动失败自动重试次数,默认是3
  7. stopasgroup=false ;默认为false,进程被杀死时,是否向这个进程组发送stop信号,包括子进程
  8. killasgroup=false ;默认为false,向进程组发送kill信号,包括子进程
  9. stdout_logfile_maxbytes=20MB ; stdout 日志文件大小,默认50MB
  10. stdout_logfile=/tmp/luffyvue.out ; 需要用户新建该目录
  1. 其他
    安装vscodium

    1. command

      1. sudo tee -a /etc/yum.repos.d/vscodium.repo << 'EOF'
      2. [gitlab.com_paulcarroty_vscodium_repo]
      3. name=gitlab.com_paulcarroty_vscodium_repo
      4. baseurl=https://paulcarroty.gitlab.io/vscodium-deb-rpm-repo/rpms/
      5. enabled=1
      6. gpgcheck=1
      7. repo_gpgcheck=1
      8. gpgkey=https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo/raw/master/pub.gpg
      9. metadata_expire=1h
      10. EOF
      11. yum -y update
      12. yum -y install vscodium
    2. link ```markdown

  2. install codium https://gitlab.com/paulcarroty/vscodium-deb-rpm-repo
  3. install Sublime Text3 https://www.sublimetext.com/docs/linux_repositories.html#yum ```

    1. 备注
      1. 127.0.0.1 是本地回环地址,部署到服务器时应该修改这部分访问路径;
      2. 替换命令的解释 s是替换命令 /替换前的内容/替换后的内容/ g=global 全局替换
      3. 全局替换npm source https://www.cnblogs.com/cythia/p/10985080.html

    2. backup of nginx configuration
  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #error_log "pipe:rollback logs/error_log interval=1d baknum=7 maxsize=2G";
  7. #pid logs/nginx.pid;
  8. events {
  9. worker_connections 1024;
  10. }
  11. http {
  12. include mime.types;
  13. default_type application/octet-stream;
  14. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. # '$status $body_bytes_sent "$http_referer" '
  16. # '"$http_user_agent" "$http_x_forwarded_for"';
  17. #access_log logs/access.log main;
  18. #access_log "pipe:rollback logs/access_log interval=1d baknum=7 maxsize=2G" main;
  19. #log_format caesar_01 '[$time_local] $remote_addr "$request" $status'
  20. log_format main_json '{"@timestamp":"$time_iso8601",'
  21. '"@version":"1",'
  22. '"server_addr":"$server_addr",'
  23. '"remote_addr":"$remote_addr",'
  24. '"host":"$host",'
  25. '"uri":"$uri",'
  26. '"body_bytes_sent":$body_bytes_sent,'
  27. '"bytes_sent":$body_bytes_sent,'
  28. '"upstream_response_time":$upstream_response_time,'
  29. '"request":"$request",'
  30. '"request_length":$request_length,'
  31. '"request_time":$request_time,'
  32. '"status":"$status",'
  33. '"http_referer":"$http_referer",'
  34. '"http_x_forwarded_for":"$http_x_forwarded_for",'
  35. '"http_user_agent":"$http_user_agent"'
  36. '}';
  37. sendfile on;
  38. #tcp_nopush on;
  39. #keepalive_timeout 0;
  40. keepalive_timeout 65;
  41. gzip on;
  42. server {
  43. listen 80;
  44. server_name localhost;
  45. charset utf-8;
  46. access_log logs/host.access.log main_json;
  47. #access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main;
  48. location / {
  49. root html;
  50. index index.html index.htm;
  51. }
  52. # /opt/tengine233/html/a/html
  53. location /a {
  54. allow 127.0.0.1;
  55. deny all;
  56. }
  57. location /b {
  58. auth_basic "登陆验证";
  59. auth_basic_user_file /etc/nginx/htpasswd;
  60. }
  61. error_page 404 /404.html;
  62. #redirect server error pages to the static page /50x.html
  63. error_page 500 502 503 504 /50x.html;
  64. location = /50x.html {
  65. root html;
  66. }
  67. }
  68. server {
  69. listen 81;
  70. server_name localhost;
  71. charset utf-8;
  72. location / {
  73. root /s25luffy/07-luffy_project_01/dist;
  74. index index.html;
  75. }
  76. }
  77. }