perfey項目服務器修改代碼注意事項: 1,靜態文件是有nginx響應的,全部的app下的static文件夾都由python3 manage.py collectstatic收集到了指定目錄 2,因此項目中的media和files這些包含大文件的內容不該放到static中 3,nginx的上傳文件大小是有限制的,須要在nginx 配置中改client_max_body_size 2000m; #最大限制爲2000M 4,修改完代碼後 1) 殺死nginx,uwsgi,supervisor 這些進程 , 查看進程 ps -ef|grep uwsgi netstat -tulpn|grep :80 殺死進程 kill -9 進程號 2) 使用 Python3 manage.py runserver 0.0.0.0:8000單獨開啓django程序,看是否有bug,可否正常運行 3) 開啓nginx 在/opt/nginx1-12 目錄下執行 sbin/nginx 4) 開啓uwsgi 在/home/perfey 項目目錄下執行 uwsgi --uwsgi 0.0.0.0:8002 --chdir=/home/perfey --module=perfey.wsgi 測試nignx + uwsgi是否正常 在瀏覽器輸入 www.perfey.top,成功後ctrl +c 關閉uwsgi 5) 使用supervisor管理Python程序 開啓supervisor supervisord -c /etc/supervisord.conf 若是報錯 Unlinking stale socket /tmp/supervisor.sock 執行unlink /tmp/supervisor.sock命令便可
報這個錯unix:///tmp/supervisor.sock refused connection 執行supervisord -c /etc/supervisord.conf 啓動項目 supervisorctl -c /etc/supervisord.conf start perfey,若是顯示已經啓動改成重啓 restart
nginx 添加rtmp-model模塊時注意服務器要開放 1935端口,配置文件見代碼 websocket是沒有跨域的問題的,因此不用考慮跨域,直接發請求進行了 uwsgi --uwsgi 0.0.0.0:8002 --chdir=/home/perfey --module=perfey.wsgi master = true processes = 5 socket=/home/perfey/perfey.sock 能夠考慮,寫兩個服務程序,一個使用nginx + uwsgi 另外一個使用django自帶的uwsiref,而後先後端分離,這樣添加功能就沒必要再原項目上改了,只需該前端的請求地址就好了,固然服務程序要使用端口號區分開來
引用博客:https://www.cnblogs.com/laifu/p/3633063.html supervisord,初始啓動Supervisord,啓動、管理配置中設置的進程。 supervisorctl stop programxxx,中止某一個進程(programxxx),programxxx爲[program:chatdemon]裏配置的值,這個示例就是chatdemon。 supervisorctl start programxxx,啓動某個進程 supervisorctl restart programxxx,重啓某個進程 supervisorctl stop groupworker: ,重啓全部屬於名爲groupworker這個分組的進程(start,restart同理) supervisorctl stop all,中止所有進程,注:start、restart、stop都不會載入最新的配置文件。 supervisorctl reload,載入最新的配置文件,中止原有進程並按新的配置啓動、管理全部進程。 supervisorctl update,根據最新的配置文件,啓動新配置或有改動的進程,配置沒有改動的進程不會受影響而重啓。 注意:顯示用stop中止掉的進程,用reload或者update都不會自動重啓 vim /etc/supervisord.conf # 在supervisord配置文件中加入如下內容 [program:perfey] command=/usr/local/python3/bin/uwsgi --uwsgi 0.0.0.0:8002 --chdir=/home/perfey --module=perfey.wsgi directory=/home/perfey startsecs=0 stopwaitsecs=0 autostart=true autorestart=true [program:chat] command=python3 manage.py runserver 0.0.0.0:8006 directory=/home/test_dwebsocket startsecs=0 stopwaitsecs=0 autostart=true autorestart=true #配置完後再從新加載 supervisorctl reload
# nginx.conf 文件 #websocket #不搞了,弄不了 #搞了幾天也沒配好websocket的nginx,不過也有收穫, #通常http請求是 nginx -> uwsgi -> django #websocket也是這樣 nginx -> uwsgi -> django (nginx能夠配置請求了,當請求路由是/chat/ws/時,就走下面的地址 59.110.140.100:8002,而後更改請求協議變爲websocket),但是怎麼傳給uwsgi是個事,我就是卡在這了 location /chat/ws/{ include /opt/nginx1-12/conf/uwsgi_params; #uwsgi_pass unix:/home/perfey/perfey.sock; proxy_pass http://59.110.140.100:8002; #proxy_redirect off; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header Origin ""; }