部署详细流程

邮差的信 提交于 2020-01-26 10:18:41
我的nginx.conf 里的代码, 注意 这个事/usr/local/nginx/conf/ 里的nginx.conf
user  root;
worker_processes  1;
events {
    worker_connections  1024;
}
http {
        include       mime.types;
        default_type  application/octet-stream;
        sendfile        on;
        keepalive_timeout  65;
        upstream django {
        #django项目的端口号 和uwsgi里面的端口号保存一致
            server 127.0.0.1:8082; # for a web port socket (we'll use this first)
        }
server {
# nginx服务的端口号 不用修改
listen 8001;
# the domain name it will serve for
# 这里可以填写你的ip地址或者域名
server_name 154.8.236.67;
charset     utf.-8;
  gzip on;
  gzip_disable "msie6";
  gzip_proxied any;
  gzip_min_length 1k;
  gzip_comp_level 4;
  gzip_types text/plain text/css application/json application/x-javascript text/javascript text/xml image/jpeg image/png image/gif;
# max upload size
client_max_body_size 75M;   # adjust to taste

# Django media
#location /media  {
#    alias /home/x/work/liebiao/lbpro/media;  # 指向django的media目录
#}

location /static {
    alias /root/Work/DailyFresh/Day_fresh/Fresh/Fresh/static/; # 指向django的static目录
}
access_log   /root/Work/DailyFresh/Day_fresh/logs/nginx_access.log;
error_log   /root/Work/DailyFresh/Day_fresh/logs/nginx_error.log;  
# Finally, send all non-media requests to the Django server.
location / {
    uwsgi_pass  django;
    include     uwsgi_params; # the uwsgi_params file you installed
    uwsgi_param UWSGI_SCRIPT Fresh.wsgi;
uwsgi_param UWSGI_CHDIR /root/Work/DailyFresh/Day_fresh/Fresh/;  # 项目的绝对路径
}
}
}
运行nginx 的代码:
启动项目,访问项目的页面。(再次提醒,注意:以下操作是在虚拟环境下进行)

进入cd /usr/local/nginx/sbin/目录

执行 ./nginx -t 命令先检查配置文件是否有错,没有错就执行以下命令,启动nginx:

./nginx

终端没有任何提示就证明nginx启动成功。

重启nginx命令:./nginx -s reload(注意:nginx启动时,才能使用该命令,否则会报错)
参考链接: https://www.cnblogs.com/opsprobe/p/10507203.html

 

uwsgi的代码[uwsgi]
#目录下文件改动时自动重启#touch-reload = 目录#Python文件改动时自动重启#py-auto-reload = 1
# Django-related settings# 项目根目录的路径chdir           = /root/Work/DailyFresh/Day_fresh/Fresh                # Django's wsgi file#wsgi-file       = Fresh/wsgi.pymodule = Fresh.wsgi:application# uwsgi服务器的角色master          = true# 进程7数processes=4# 线程数threads=2# 存放进程编号的文件pidfile= uwsgi.pid# the socket (use the full path to be safesocket=:8082#http          = 127.0.0.1:8002#stats = 127.0.0.1:9191# ... with appropriate permissions - may be needed#chmod-socket    = 664# clear environment on exitvacuum          = true# 日志文件,因为uwsgi可以脱离终端在后台运行,日志看不见。我们以前的runserver是依赖终端的daemonize=uwsgi.log# 虚拟环境的目录pythonpath = /root/.local/share/virtualenvs/Day_fresh-KKzeP8YR/
uwsgi开启命令: uwsgi -i uwsgi.ini
wsgi --stop uwsgi.pid  # 停止

查看8000端口是否占用: lsof -i:8000

 

第一步:ssh进入到服务器, 首先安装项目中用到的Python版本, 我的项目是Python3.6.2  安装参考链接: https://www.jianshu.com/p/7a76bcc401a1 (实测没有问题)

第二步: 回到cd ~ 用pip install pipenv  然后 设置软连接: ln -s /usr/local/python3.6/bin/pipenv /usr/bin/pipenv

第三步: 下载mysql  参考链接: https://www.cnblogs.com/nicknailo/articles/8563737.html

第四步: git clone 或者SVN  到服务器上项目

第五步: cd 到pipfile目录下 , 创建虚拟环境 pipenv shell , 然后 pipenv install django  进行一系列的配置 安装,  保证./manage.py runserver没有错误

第六步: 安装zsh 和 oh-my-zsh 还有自动补全插件(自行百度)

第七步: 剩下的步骤 按照这个来 https://www.cnblogs.com/lvye001/p/10631276.html

 

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!