{"id":248840,"date":"2022-08-09T10:10:59","date_gmt":"2022-08-09T02:10:59","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=248840"},"modified":"2022-07-29T14:11:29","modified_gmt":"2022-07-29T06:11:29","slug":"centos-nginx-uwsgi","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/centos-nginx-uwsgi.html","title":{"rendered":"centos+nginx+uwsgi\u90e8\u7f72django\u9879\u76ee\u4e0a\u7ebf\u8be6\u89e3"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u672c\u6587\u4e3b\u8981\u4ecb\u7ecd\u4e86centos+nginx+uwsgi\u90e8\u7f72django\u9879\u76ee\u4e0a\u7ebf\uff0c\u6587\u4e2d\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u4ecb\u7ecd\u7684\u975e\u5e38\u8be6\u7ec6\uff0c\u5bf9\u5927\u5bb6\u7684\u5b66\u4e60\u6216\u8005\u5de5\u4f5c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u5b66\u4e60\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u4eec\u4e0b\u9762\u968f\u7740\u5c0f\u7f16\u6765\u4e00\u8d77\u5b66\u4e60\u5b66\u4e60\u5427<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u4e0a\u4f20\u5b8c\u6574django\u9879\u76ee\u6587\u4ef6\u5230\u670d\u52a1\u5668<\/p>\n

sftp ftp lrzsz\u90fd\u53ef\u4ee5\u4e0a\u4f20\u6587\u4ef6\u5230\u670d\u52a1\u5668\uff0c\u770b\u81ea\u5df1<\/p>\n

\u6211django\u9879\u76ee\u53ebyunwei,\u4e3b\u8981app\u662frabc\u548cweb,\u6574\u4e2a\u9879\u76ee\u653e\/opt\/\u4e0b<\/p>\n

\u5982\u4e0b\uff1a<\/p>\n

[root@test-code opt]# ls\r\ndjango_virt  nginx  redis  redis-6.2.6  yunwei\r\n[root@test-code opt]# ls yunwei\/\r\nmanage.py  rbac  static  templates  uwsgi  web  yunwei\r\n[root@test-code opt]# ls yunwei\/uwsgi\/\r\ncut_log.sh  log  uwsgi.ini  uwsgi.log  uwsgi.pid  uwsgi.sock\r\n[root@test-code opt]#<\/pre>\n

\/opt\/yunwei\/\u5c31\u662f\u6211\u7684django\u9879\u76ee\u7684\u6839\u76ee\u5f55\uff0cmanage.py\u5c31\u662f\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\uff0c\/opt\/yunwei\/\u4e0b\u6709\u4e00\u4e2a\u540c\u540d\u5b50\u76ee\u5f55yunwei,\u4e0b\u9762\u6709\u4e00\u4e2asetting.py\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n

Python\u5b89\u88c5<\/strong><\/div>\n

\u5982\u679c\u7528\u5230\u7684python\u7248\u672c\u662f2\uff0c\u4e0d\u9700\u8981\u91cd\u65b0\u5b89\u88c5\uff0c\u5982\u679c\u662f3,\u90a3\u4e48\u9700\u8981\u91cd\u65b0\u5b89\u88c5\uff0c\u53c2\u7167\uff1acentos\u5b89\u88c5python3.8<\/p>\n

django\u76f8\u5173\u5e93\u7684\u5b89\u88c5<\/strong><\/div>\n
#\u5728\u539f\u9879\u76ee\u5904\u5bfc\u51fadjango\u9879\u76ee\u5b89\u88c5\u7684\u5e93\u5b58\u5165\u6587\u4ef6\r\npip freeze > install.txt<\/pre>\n

\u628a\u6587\u4ef6\u653e\u5230\u9700\u8981\u90e8\u7f72\u7684\u670d\u52a1\u5668\u4e0a\uff0c\u5e76\u5b89\u88c5\u6587\u4ef6\u5185\u7684\u5305<\/p>\n

#\u5728\u5f85\u90e8\u7f72\u7684\u670d\u52a1\u5668\u4e0a\u6267\u884c\r\npip install -r install.txt<\/pre>\n
nginx\u5b89\u88c5&\u914d\u7f6e(\u5904\u7406\u9759\u6001\u8bf7\u6c42\u548c\u4ee3\u7406\u52a8\u6001\u8bf7\u6c42\u5230uwsgi)<\/strong><\/div>\n

nginx\u5b89\u88c5\u53c2\u7167\uff1alinux\u5b89\u88c5nginx<\/p>\n

nginx\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b<\/p>\n

[root@test-code opt]# cat \/opt\/nginx\/conf.d\/django.conf \r\nserver {\r\n       listen 8881;\r\n       server_name localhost;\r\n       server_tokens off;       \r\n    location \/static {\r\n                root  \/opt\/yunwei;\r\n                index  index.html index.htm;\r\n                }\r\n    location \/ {\r\n            include uwsgi_params; #nginx\u52a0\u8f7duwsgi\u6a21\u5757\r\n            uwsgi_buffer_size 16k;\r\n            uwsgi_busy_buffers_size 24k;\r\n            #\u5982\u679c\u4f60\u540e\u7aef\u7684\u9700\u8981\u8d85\u8fc760\u79d2\u65f6\u95f4\u5904\u7406\u8bf7\u6c42\uff0c\u90a3\u4e48\u4e00\u5b9a\u8981\u52a0\u4e0a\u4e0b\u9762\u4e09\u4e2a\u8d85\u65f6\u65f6\u95f4\u7684\u8bbe\u7f6e\uff0c\u4e0d\u713660s\u4e4b\u540enginx\u65ad\u5f00\u94fe\u63a5\u62a5\u8d85\u65f6\r\n            uwsgi_send_timeout 600;        # \u6307\u5b9a\u5411uWSGI\u4f20\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u5b8c\u6210\u63e1\u624b\u540e\u5411uWSGI\u4f20\u9001\u8bf7\u6c42\u7684\u8d85\u65f6\u65f6\u95f4\u3002\r\n            uwsgi_connect_timeout 600;   # \u6307\u5b9a\u8fde\u63a5\u5230\u540e\u7aefuWSGI\u7684\u8d85\u65f6\u65f6\u95f4\u3002\r\n            uwsgi_read_timeout 600;        # \u6307\u5b9a\u63a5\u6536uWSGI\u5e94\u7b54\u7684\u8d85\u65f6\u65f6\u95f4\uff0c\u5b8c\u6210\u63e1\u624b\u540e\u63a5\u6536uWSGI\u5e94\u7b54\u7684\u8d85\u65f6\u65f6\u95f4\u3002 \r\n            uwsgi_pass unix:\/opt\/yunwei\/uwsgi\/uwsgi.sock; #nginx\u5bf9\u5e94\u7684uwsgi socket\u6587\u4ef6\r\n        }\r\n \r\n}<\/pre>\n
uwsgi\u5b89\u88c5&\u914d\u7f6e<\/strong><\/div>\n
pip install uwsgi<\/pre>\n

\u5728django\u7684\u9879\u76ee\u76ee\u5f55\u4e0b\/opt\/yunwei\/\u521b\u5efa\u4e00\u4e2auwsgi\u7684\u76ee\u5f55\u7528\u4e8e\u5b58\u653euwsgi\u76f8\u5173\u7684\u6587\u4ef6\u3002<\/p>\n

cd \/opt\/yunwei\/ && mkdir uwsgi\r\ntouch uwsgi\/uwsgi.ini<\/pre>\n

\u521b\u5efa\u914d\u7f6e\u6587\u4ef6<\/p>\n

[root@test-code yunwei]# cat uwsgi\/uwsgi.ini \r\n[uwsgi]\r\n#django\u9879\u76ee\u7684\u6839\u76ee\u5f55\uff0c\u5373manage.py\u6240\u5728\u7684\u76ee\u5f55\r\nchdir=\/opt\/yunwei\r\n#django\u9879\u76ee\u7684wsgi\uff0cyuwnei\u7684\u9879\u76ee\u540d\r\nmodule=yunwei.wsgi:application\r\nsocket=\/opt\/yunwei\/uwsgi\/uwsgi.sock\r\n#\u8fd9\u91cc\u662f\u6211\u7684python\u865a\u62df\u73af\u5883\uff0c\u53ef\u4ee5\u4e0d\u914d\u7f6e\r\nhome=\/opt\/django_virt\r\n#\u8fdb\u7a0b\u6570\r\nworkers=5\r\n#pid\u6587\u4ef6\u8def\u5f84\r\npidfile=\/opt\/yunwei\/uwsgi\/uwsgi.pid\r\n#IP\u7aef\u53e3\r\nsocket = 0.0.0.0:8000\r\nmaster=true\r\n#\u9000\u51fa\u6e05\u7406\u6587\u4ef6\r\nvacuum=true\r\n#\u542f\u7528\u7ebf\u7a0b\r\nenable-threads=true\r\n#\u5e8f\u5217\u5316\u63a5\u53d7\u7684\u5185\u5bb9\uff0c\u5982\u679c\u53ef\u80fd\u7684\u8bdd\r\nthunder-lock=true\r\n#\u8bbe\u7f6e\u81ea\u4e2d\u65ad\u65f6\u95f4\uff0c\u5982\u679c\u540e\u7aef\u5904\u7406\u4e00\u4e9b\u8bf7\u6c42\u65f6\u95f4\u6bd4\u8f83\u957f\uff0c\u8fd9\u4e2a\u4e00\u5b9a\u8981\u8bbe\u7f6e\u5927\u4e00\u70b9\r\nharakiri=3600 #\r\nsocket-timeout=3600 #\u8fd9\u4e2a\u662f\u548cnginx\u642d\u914d\u90e8\u7f72\u65f6\u7684\u8bbe\u7f6e\r\nhttp-timeout=3600 #\u8fd9\u4e2a\u662f\u5355\u72ec\u90e8\u7f72\u65f6\u7684\u8bbe\u7f6e\r\n#\u8bbe\u7f6e\u7f13\u51b2\r\npost-buffering=65535\r\nbuffer-size = 6553600\r\n#\u540e\u53f0\u5b88\u62a4\u65b9\u5f0f\u8fd0\u884c\uff0c\u65e5\u5fd7\u8def\u5f84\r\ndaemonize=\/opt\/yunwei\/uwsgi\/uwsgi.log<\/pre>\n
\u6807\u9898\u5173\u95edsetting.py\u7684DEBUG\u6a21\u5f0f<\/strong><\/div>\n
vim \/opt\/yunwei\/yunwei\/setting.py\r\n \r\nDEBUG = True #\u6539\u4e3a DEBUG = False<\/pre>\n

debug\u6a21\u5f0f\u4e3aTrue\u65f6\uff0cdjango\u4f1a\u81ea\u5df1\u5904\u7406static\u7684\u9759\u6001\u8bf7\u6c42\uff0c\u73b0\u5728\u662fnginx\u53bb\u5904\u7406\u8fd9\u4e9b\u8bf7\u6c42\uff0c\u6545\u4e3aFalse<\/p>\n

\u505a\u5b8c\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u53ea\u9700\u8981\u542f\u52a8uwsgi\u548cnginx\u5373\u53ef\uff0c\u901a\u8fc7nginx listen\u7aef\u53e3\u53bb\u8bbf\u95ee<\/p>\n

#uwsgi \u542f\u52a8\u547d\u4ee4 \r\nuwsgi --ini \/opt\/yunwei\/uwsgi\/uwsgi.ini\r\n#uwsgi \u91cd\u542f\u547d\u4ee4 \r\nuwsgi --reload \/opt\/yunwei\/uwsgi\/uwsgi.ini\r\nuwsgi\u7684\u65e5\u5fd7\u6587\u4ef6\u5728\/opt\/yunwei\/uwsgi\/uwsgi.log\u5904<\/pre>\n

\u53ef\u4ee5\u901a\u8fc7 ss -tnulp | grep uwsgi \u53bbkill -9 \u8fdb\u7a0bID\u53bb\u6740\u6389\u8fdb\u7a0b<\/p>\n

#\u542f\u52a8nginx\r\nnginx\r\n#\u91cd\u542f\r\nnginx -s reload\r\n#\u5173\u95ed\r\nnginx -s stop\r\n#\u68c0\u6d4b\u914d\u7f6e\u6587\u4ef6\u662f\u5426\u6b63\u786e\r\nnginx -t<\/pre>\n

\u641e\u5b9a\uff0c\u4f5c\u6b64\u8bb0\u5f55\u3002\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8ecentos+nginx+uwsgi\u90e8\u7f72django\u9879\u76ee\u4e0a\u7ebf\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86<\/p>\n","protected":false},"excerpt":{"rendered":"

\u4e0a\u4f20\u5b8c\u6574django\u9879\u76ee\u6587\u4ef6\u5230\u670d\u52a1\u5668 sftp ftp lrzsz\u90fd\u53ef\u4ee5\u4e0a\u4f20\u6587\u4ef6\u5230\u670d\u52a1\u5668\uff0c\u770b\u81ea\u5df1 \u6211djang […]<\/p>\n","protected":false},"author":362,"featured_media":244922,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-248840","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/362"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=248840"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248840\/revisions"}],"predecessor-version":[{"id":248843,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/248840\/revisions\/248843"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/244922"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=248840"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=248840"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=248840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}