后端搞起python
pip3 install -i https://pypi.douban.com/simple uwsgi
source s21Django1/bin/activate #激活 virtualenv --no-site-packages --python=python3 s21uwsgi #这是建立虚拟环境
使用uwsgi的命令,参数形式启动 crm项目mysql
uwsgi --http :8000 --module mysite.wsgi --http 指定是http协议,去启动项目 --module 指定django目录下的wsgi文件 #这样加载的 没法加载静态文件
uwsgi --http :9000 --module Aida_crm.wsgi --py-autoreload=1
uwsgi以配置文件的形式启动 ,就是把你的启动参数,写入到一个文件中,而后,执行这个文件便可linux
[uwsgi] # Django-related settings # the base directory (full path) #填入项目的绝对路径 ,项目的第一层路径 chdir = /opt/s21/Aida_crm # Django's wsgi file #指定第二层项目下的wsgi文件 module = Aida_crm.wsgi # the virtualenv (full path) #找到虚拟环境的绝对路径 home = /opt/s21/s21uwsgi # process-related settings # master master = true # 以cpu核数来填写,uwsgi的工做进程数 processes = 2 # the socket (use the full path to be safe #这是以uwsgi_socket协议启动的项目,没法再去经过浏览器访问,必须经过nginx以uwsgi协议去反向代理 socket = 0.0.0.0:8000 #也能够使用http协议去启动(仅用做调试使用) #http = 0.0.0.0:9000 # ... with appropriate permissions - may be needed # chmod-socket = 664 # clear environment on exit vacuum = true #后台运行参数,将uwsgi运行在后台,而且将django日志输出到uwsgi.log中 daemonize = uwsgi.log
指定配置文件启动djangonginx
uwsgi --ini uwsgi.ini #到这里 配置文件生效 项目已经启动 由于使用了socket 因此必须使用nginx反向代理
server { listen 80; server_name www.oldchouhuo.com; #charset koi8-r; #access_log logs/host.access.log main; #access_log "pipe:rollback logs/host.access_log interval=1d baknum=7 maxsize=2G" main; location / { #转发请求的方式配置在这里 #转发请求的方式配置在这里 #转发请求的方式配置在这里 include uwsgi_params; uwsgi_pass 0.0.0.0:8000; } }
去浏览器访问nginx的地址,查看可否访问到crm的内容 #注意: 去将要访问的电脑修改host host文件在 c:windows/system32/driver/etc/hosts 添加 192.168.108.130 域名(www.oldchouhuo.com)
#对django的settings.py配置修改以下 #添加以下参数 STATIC_ROOT='/opt/s21static' STATIC_URL = '/static/' STATICFILES_DIRS = [ os.path.join(BASE_DIR, 'static') ] 执行命令,收集django的全部静态文件,系统会自动建立'/opt/s21static' 这个文件夹 python3 manage.py collectstatic
location / { include uwsgi_params; uwsgi_pass 0.0.0.0:8000; } #添加一个location,针对nginx的url进行匹配处理 #当请求时 www.oldchouhuo.com/static/..... 这样的url的时候,nginx进行别名修改,去/opt/s21static底下去寻找资源文件 location /static { alias /opt/s21static; }