Skip to content

Commit

Permalink
Update 第39节相关命令.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
HaddyYang authored Mar 3, 2020
1 parent 2b45a52 commit af27216
Showing 1 changed file with 41 additions and 32 deletions.
73 changes: 41 additions & 32 deletions 39.用Nginx+uWSGI部署/第39节相关命令.txt
Original file line number Diff line number Diff line change
@@ -1,41 +1,50 @@
1����װuwsgi
ע�⣺
1����ϵͳ������װ�������⻷��
2��ʹ�ö�Ӧpython�汾��װ
3��Ҫ�Ȱ�װpython������
1、安装uwsgi
注意:
1)在系统环境安装,非虚拟环境
2)使用对应python版本安装
3)要先安装python开发包

pip3 install uwsgi


2������ uwsgi �Ƿ�������
�½� test.py �ļ����������£�
2、测试 uwsgi 是否正常:
新建 test.py 文件,内容如下:
def application(env, start_response):
start_response('200 OK', [('Content-Type','text/html')])
return "Hello World"

Ȼ�����ն����У�
然后在终端运行:
uwsgi --http :8001 --wsgi-file test.py
ע�⣺��Ҫ�����˿ڲſ�����������
注意:需要开启端口才可以正常访问


3��������uwsgi��httpЭ�����djangoд����վ
ִ������������Բ����Լ�����Ŀ
3、可以用uwsgi的http协议访问django写的网站
执行如下命令可以测试自己的项目
uwsgi --http :8001 --chdir /home/mysite --home /home/mysite_env --module mysite.wsgi:application

* 参数说明:
chdir:指向程序的根目录
home:虚拟环境的路径,若没有虚拟环境,可以不写该参数
module:要使用的wsgi模块

4����װnginx
���а�װ��apache��Ҫ�Ȱ�apache����ر�(apache2ctl stop)
* 特别说明
和Lucas的一次调试,发现命令行有时需要用env参数,设置环境遍历。例如
uwsgi --http :8001 --chdir /home/mysite --home /home/mysite_env --module mysite.wsgi:application --env DJANGO_SETTINGS_MODULE=mysite.settings


4、安装nginx
若有安装过apache,要先把apache服务关闭(apache2ctl stop)
apt-get update
apt-get install nginx

�Ƴ�default
移除default
/etc/nginx/sites-enabled/default

����sites-available�����µ�����
进入sites-available创建新的配置
cd /etc/nginx/sites-available/
vim mysite.conf

���ÿ��Բο����棺
配置可以参考下面:
server {
listen 80;
server_name mysite;
Expand All @@ -57,11 +66,11 @@ server {
}
}

�����������ӵ�sites-enabled
再设置软链接到sites-enabled
ln -s /etc/nginx/sites-available/mysite.conf /etc/nginx/sites-enabled/mysite.conf


5������uwsgi������ini�ļ����㴦����ini�ο����£�
5、配置uwsgi,创建ini文件方便处理。ini参考如下:
[uwsgi]
chdir = /home/mysite
home = /home/mysite_env
Expand All @@ -81,25 +90,25 @@ daemonize = /home/mysite_uwsgi/mysite.log
vacuum = True


6������uwsgi
6、启动uwsgi
uwsgi --ini /home/mysite_uwsgi/mysite.ini


7������nginx
7、重启nginx
service nginx restart


=======================
�������
nginx�������nginx -t
�鿴uwsgi���̣�ps -aux | grep uwsgi
�����ر�uwsgi���̣�uwsgi --stop /home/mysite_uwsgi/master.pid
ǿ�ƹر�ȫ��uwsgi���̣�ps -aux | grep uwsgi |awk '{print $2}'|xargs kill -9
���¼���uwsgi��uwsgi --reload /home/mysite_uwsgi/master.pid

�ο��ĵ���
��Django������https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/uwsgi/
��uwsgi���ģ�https://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/tutorials/Django_and_nginx.html
��uwsgiӢ�ģ�https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
����ǿѧ�ã�https://code.ziqiangxuetang.com/django/django-nginx-deploy.html
其他参考:
nginx测试命令:nginx -t
查看uwsgi进程:ps -aux | grep uwsgi
正常关闭uwsgi进程:uwsgi --stop /home/mysite_uwsgi/master.pid
强制关闭全部uwsgi进程:ps -aux | grep uwsgi |awk '{print $2}'|xargs kill -9
重新加载uwsgi:uwsgi --reload /home/mysite_uwsgi/master.pid

参考文档:
(Django官网)https://docs.djangoproject.com/en/2.1/howto/deployment/wsgi/uwsgi/
(uwsgi中文)https://uwsgi-docs-zh.readthedocs.io/zh_CN/latest/tutorials/Django_and_nginx.html
(uwsgi英文)https://uwsgi.readthedocs.io/en/latest/tutorials/Django_and_nginx.html
(自强学堂)https://code.ziqiangxuetang.com/django/django-nginx-deploy.html

0 comments on commit af27216

Please sign in to comment.