{"id":32823,"date":"2023-03-25T20:53:49","date_gmt":"2023-04-15T10:43:02","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/"},"modified":"2024-04-29T20:29:53","modified_gmt":"2024-04-29T12:29:53","slug":"%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/","title":{"rendered":"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883"},"content":{"rendered":"<h1>\u4f60\u53ea\u9700\u8981\u7528\u4e2d\u6587\u8f6c\u8ff0\u8fd9\u4e2a\u6982\u8981\u7684\u4e00\u4e2a\u9009\u62e9\u3002<\/h1>\n<p>\u5728\u521b\u5efaDjango\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u5728\u5c06\u5176\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff08\u672c\u5730\uff09\u65f6\uff0c\u6211\u9047\u5230\u4e86\u4e00\u4e9b\u95ee\u9898\uff0c\u6240\u4ee5\u6211\u5c06\u8bb0\u5f55\u4e0b\u6765\u4ee5\u5907\u5907\u5fd8\u3002<br \/>\n\u4f5c\u4e3a\u6211\u9047\u5230\u7684\u95ee\u9898\uff0cDjango\u5e94\u7528\u7a0b\u5e8f\u548cNginx\u7684\u8fde\u63a5\u672a\u6b63\u5e38\u5de5\u4f5c\uff0c\u5bfc\u81f4\u672c\u5e94\u663e\u793a\u7684\u9875\u9762\u5b9e\u9645\u4e0a\u663e\u793a\u4e86Hello\u9875\u9762\uff08\u9ed8\u8ba4\u9875\u9762\uff09\u3002<br \/>\n\u5982\u679c\u6709\u5176\u4ed6\u4eba\u4e5f\u9047\u5230\u4e86\u540c\u6837\u7684\u95ee\u9898\u6216\u8005\u6253\u7b97\u505a\u540c\u6837\u7684\u4e8b\u60c5\uff0c\u5e0c\u671b\u8fd9\u4e9b\u8bb0\u5f55\u5bf9\u4ed6\u4eec\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<p>\u6211\u5e0c\u671b\u6211\u7684\u89e3\u91ca\u53ef\u4ee5\u8ba9\u4efb\u4f55\u4eba\u90fd\u80fd\u7406\u89e3\uff0c\u4f46\u662f\u6211\u8ba4\u4e3a\u9700\u8981\u4e00\u5b9a\u7684Django\u77e5\u8bc6\u3002<\/p>\n<h1>\u5047\u8bbe<\/h1>\n<p>\u524d\u63d0\u662f\u5b8c\u6210 Django \u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u3001\u5b89\u88c5 MySQL\u3001\u5b89\u88c5 Nginx\u3002\u5982\u679c\u65e0\u6cd5\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u8bf7\u53c2\u8003\u8fd9\u4e9b\u6587\u7ae0\u8fdb\u884c\u914d\u7f6e\u3002<\/p>\n<p>MySQL\u7684\u5efa\u7acb<\/p>\n<p>&nbsp;<\/p>\n<p>\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684nginx\uff1a<\/p>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u30d5\u30ec\u30fc\u30e0\u30ef\u30fc\u30af: Django == 4.2.5<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">DB: MySQL == 8.0.34<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">AP\u30b5\u30fc\u30d0: Gunicorn == 21.2.0<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Web\u30b5\u30fc\u30d0: Nginx == 1.24.0<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">Python: python3.10.12<\/ul>\n<h1>\u5728\u4f7f\u7528\u73af\u5883\u4e2d\u3002<\/h1>\n<p>\u6211\u8ba4\u4e3a\u6700\u91cd\u8981\u7684\u662f\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0c\u4f46\u6211\u4f1a\u8fdb\u884c\u8bb0\u5f55\u3002<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">server<\/ul>\n<\/li>\n<\/ul>\n<p>OS: Ubuntu22.04 LTS<\/p>\n<p>client<\/p>\n<p>OS: MacOS Ventura 13.4.1(c)<\/p>\n<h1>\u6784\u60f3<\/h1>\n<p>\u6211\u6309\u7167\u4ee5\u4e0b\u7684\u6784\u60f3\u8fdb\u884c\u4e86\u5b9e\u65bd\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d13d437434c4406bf99dc\/15-0.jpeg\" alt=\"server_image_page-0001.jpg\" \/><\/div>\n<h1>\u76ee\u5f55\u7ed3\u6784\u6784\u60f3<\/h1>\n<p>\u552f\u4e00\u91cd\u8981\u7684\u662fyourproject\/yourproject\/settings.py\u3002app1\u7b49\u6307\u7684\u662f\u5404\u81ea\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"o\">.<\/span>\r\n<span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">bin<\/span> <span class=\"c1\"># \u4eee\u60f3\u74b0\u5883<\/span>\r\n<span class=\"err\">\u2514\u2500\u2500<\/span> <span class=\"n\">yourproject<\/span> <span class=\"c1\"># \u305d\u308c\u305e\u308c\u306e\u30d7\u30ed\u30b8\u30a7\u30af\u30c8<\/span>\r\n    <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">app1<\/span>\r\n    <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">app2<\/span>\r\n    <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">app3<\/span>\r\n    <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">yourproject<\/span>\r\n    <span class=\"err\">\u2502\u00a0\u00a0<\/span> <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">__init__<\/span><span class=\"p\">.<\/span><span class=\"nf\">py<\/span>\r\n    <span class=\"err\">\u2502\u00a0\u00a0<\/span> <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">asgi<\/span><span class=\"p\">.<\/span><span class=\"nf\">py<\/span>\r\n    <span class=\"err\">\u2502\u00a0\u00a0<\/span> <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">settings<\/span><span class=\"p\">.<\/span><span class=\"nf\">py<\/span> <span class=\"c1\"># \u4eca\u56de\u306f\u3053\u3053\u3060\u3051\u5909\u66f4\u3057\u307e\u3059<\/span>\r\n    <span class=\"err\">\u2502\u00a0\u00a0<\/span> <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">urls<\/span><span class=\"p\">.<\/span><span class=\"nf\">py<\/span>\r\n    <span class=\"err\">\u2502\u00a0\u00a0<\/span> <span class=\"err\">\u2514\u2500\u2500<\/span> <span class=\"n\">wsgi<\/span><span class=\"p\">.<\/span><span class=\"nf\">py<\/span>\r\n    <span class=\"err\">\u2514\u2500\u2500<\/span> <span class=\"n\">templates<\/span>\r\n        <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">app1<\/span>\r\n        <span class=\"err\">\u251c\u2500\u2500<\/span> <span class=\"n\">app2<\/span>\r\n        <span class=\"err\">\u2514\u2500\u2500<\/span> <span class=\"n\">app3<\/span>\r\n\r\n<\/code><\/pre>\n<h1>\u64cd\u4f5c\u6b65\u9a5f<\/h1>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u521b\u5efaDjango\u5e94\u7528\u7a0b\u5e8f\uff08\u8fd9\u91cc\u7701\u7565\uff09<\/ol>\n<\/li>\n<\/ol>\n<p>\u66f4\u65b0apt\u548cpip<br \/>\nsudo apt update<br \/>\npython3 -m pip install &#8211;upgrade pip<\/p>\n<p>\u5b89\u88c5virtualenv<br \/>\npython3 -m pip install virtualenv<\/p>\n<p>\u8bbe\u7f6e\u548c\u6fc0\u6d3b\u865a\u62df\u73af\u5883<br \/>\n$ sudo apt install python3.10-venv<br \/>\n$ python3 -m venv .<br \/>\n$ source bin\/activate<\/p>\n<p>\u5b8c\u6210\u540e\uff0c\u5728\u7ec8\u7aef\u7684\u7528\u6237\u540d\u4e4b\u524d\u5e94\u8be5\u663e\u793a\u4e3a\u50cf&#8221;(\u6b63\u5728\u5de5\u4f5c\u7684\u76ee\u5f55\u540d)hoge@hoge:~\/&#8230;$&#8221;\u8fd9\u6837\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u5b89\u88c5\u865a\u62df\u73af\u5883\u6240\u9700\u7684\u8f6f\u4ef6<br \/>\n$ python3 -m pip install django gunicorn psycopg2-binary<br \/>\n$ sudo apt install curl<\/p>\n<p>\u4e0a\u8ff0\u5185\u5bb9\u662f\u5fc5\u9700\u7684\u3002<br \/>\n\u8fd8\u53ef\u4ee5\u968f\u65f6\u5b89\u88c5\u5176\u4ed6\u6240\u9700\u7684\u8f6f\u4ef6\uff0c\u56e0\u4e3a\u5728\u8fd0\u884crunserver\u65f6\u4f1a\u663e\u793a\u6240\u7f3a\u5c11\u7684\u5185\u5bb9\u3002<\/p>\n<p>\u7f16\u8f91Django\u5e94\u7528\u7684settings.py<\/p>\n<p>yourproject\/yourproject\/settings.py<br \/>\n$ cd yourproject\/yourproject<br \/>\n$ vi settings.py<\/p>\n<p>\uff03\u8bf7\u7f16\u8f91\u4ee5\u4e0b\u90e8\u5206<br \/>\nALLOWED_HOSTS = [&#8216;*&#8217;]<\/p>\n<p>#\u5c06\u5bfc\u5165\u653e\u5728\u6587\u4ef6\u5f00\u5934<br \/>\nimport os<br \/>\nSTATIC_URL = &#8216;\/static\/&#8217;<br \/>\nSTATIC_ROOT = os.path.join(BASE_DIR, &#8216;static\/&#8217;)<\/p>\n<p>\u7f16\u8f91\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u7f16\u8f91\u5668\u90fd\u53ef\u4ee5\uff0c\u5305\u62ecvscode\u3002<\/p>\n<p>\u672c\u6b21\u4e0d\u8003\u8651\u5b89\u5168\u6027\u3002\u56e0\u6b64\uff0cALLOWED_HOSTS = [&#8216;*&#8217;]\uff0c\u4f46\u5b9e\u9645\u4e0a\u5e94\u53ea\u5141\u8bb8\u4f7f\u7528\u7684IP\u3002<\/p>\n<p>\u8fc1\u79fb\u6570\u636e\u5e93\u5e76\u521b\u5efa\u7ba1\u7406\u5458\u7528\u6237<\/p>\n<p>yourproject<br \/>\n$ python3 manage.py makemigrations<br \/>\n$ python3 manage.py migrate<br \/>\n$ python3 manage.py createsuperuser<br \/>\n#\u63a7\u5236\u53f0\u4f1a\u663e\u793a\u5404\u79cd\u5185\u5bb9\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a\u4e0d\u53ef\u731c\u6d4b\u7684\u7528\u6237\u3002<\/p>\n<p>\u5982\u679c\u5df2\u7ecf\u521b\u5efa\u4e86\u8fc1\u79fb\u548c\u7ba1\u7406\u5458\u7528\u6237\uff0c\u53ef\u4ee5\u8df3\u8fc7\u6b64\u6b65\u9aa4\u3002<\/p>\n<p>\u6536\u96c6\u9759\u6001\u6587\u4ef6<\/p>\n<p>yourproject<br \/>\n$ python3 manage.py collectstatic<\/p>\n<p>\u9632\u706b\u5899\u8bbe\u7f6e<\/p>\n<p>yourproject<br \/>\n$ sudo ufw allow 8000<\/p>\n<p>\u68c0\u67e5Django\u5e94\u7528\u662f\u5426\u542f\u52a8<\/p>\n<p>yourproject<br \/>\n$ python3 manage.py runserver<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u4f7f\u7528Gunicorn\u542f\u52a8<\/p>\n<p>yourproject<br \/>\n$ gunicorn &#8211;bind 0.0.0.0:8000 yourproject.wsgi<\/p>\n<p>\u5728settings.py\u6240\u5728\u7684\u76ee\u5f55\u4e2d\u79fb\u52a8\u5e76\u6267\u884c\u6b64\u547d\u4ee4\u3002<br \/>\n\u9996\u5148\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00http:\/\/your_ip:8000\uff0c\u5982\u679c\u770b\u5230\u5e94\u7528\u7a0b\u5e8f\u754c\u9762\uff0c\u5219\u8868\u793a\u6b63\u5e38\u3002<\/p>\n<p>\u521b\u5efasystemd\u5957\u63a5\u5b57<br \/>\n$ sudo vi \/etc\/systemd\/system\/gunicorn.socket<\/p>\n<p>#\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9<br \/>\n[Unit]<br \/>\nDescription=gunicorn socket<br \/>\n[Socket]<br \/>\nListenStream=\/run\/gunicorn.sock<br \/>\n[Install]<br \/>\nWantedBy=sockets.target<\/p>\n<p>\u521b\u5efa\u670d\u52a1\u6587\u4ef6<br \/>\n$ sudo vi \/etc\/systemd\/system\/gunicorn.service<\/p>\n<p>#\u4f7f\u7528\u9002\u5f53\u7684\u66f4\u6539\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9\uff08\u8bf7\u5220\u9664&#8221;()&#8221;\uff09<br \/>\n[Unit]<br \/>\nDescription=gunicorn daemon<br \/>\nRequires=gunicorn.socket<br \/>\nAfter=network.target<br \/>\n[Service]<br \/>\nUser=sammy\uff08Ubuntu\u7528\u6237\u540d\uff09<br \/>\nGroup=sammy\uff08\u4f7f\u7528Ubuntu\u7528\u6237\u540d\uff09<br \/>\nWorkingDirectory=\/home\/sammy\/yourprojectdir\uff08settings.py\u7684\u4e0a\u7ea7\u8def\u5f84\uff09<br \/>\nExecStart=\/home\/sammy\/yourprojectdir\/bin\/gunicorn \\\uff08bin\/gunicorn\u7684\u8def\u5f84\uff09<br \/>\n&#8211;access-logfile &#8211; \\<br \/>\n&#8211;workers 3 \\<br \/>\n&#8211;bind unix:\/run\/gunicorn.sock \\<br \/>\nyourproject.wsgi:application\uff08yourproject\u662f\u521b\u5efa\u7684\u5e94\u7528\u7a0b\u5e8f\u540d\u79f0\uff09<br \/>\n[Install]<br \/>\nWantedBy=multi-user.target<\/p>\n<p>\u5176\u4ed6\u8bbe\u7f6e\uff08\u8d85\u65f6\u7b49\uff09\u8bf7\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002<br \/>\nhttps:\/\/docs.gunicorn.org\/en\/stable\/settings.html<\/p>\n<p>\u6267\u884cGunicorn\u5957\u63a5\u5b57\u5e76\u6fc0\u6d3b\u5957\u63a5\u5b57<br \/>\n$ sudo systemctl start gunicorn.socket<br \/>\n$ sudo systemctl enable gunicorn.socket<br \/>\n$ sudo systemctl status gunicorn.socket<\/p>\n<p>\u5982\u679c\u72b6\u6001\u663e\u793a\u4e3aActive\u4e3aactive\uff0c\u5219\u8868\u793a\u6b63\u5e38\u3002\u5176\u4ed6\u4fe1\u606f\u4e3a\u7eff\u8272\u7684\u26aa\ufe0e\u8868\u793a\u542f\u52a8\u5b8c\u6210\u3002<\/p>\n<p>\u68c0\u67e5\u662f\u5426\u5b58\u5728gunicorn.sock\u6587\u4ef6<br \/>\n$ file \/run\/gunicorn.sock<br \/>\n#\u5982\u679c\u663e\u793a\u4e0b\u9762\u7684\u5185\u5bb9\uff0c\u5219\u8868\u793a\u6b63\u5e38<br \/>\n\/run\/gunicorn.sock: socket<\/p>\n<p>\u5982\u679c\u9047\u5230\u95ee\u9898\uff0c\u8bf7\u68c0\u67e5\u662f\u5426\u5df2\u521b\u5efa\u5957\u63a5\u5b57\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u8c03\u8bd5\u3002<br \/>\n$ sudo journalctl -u gunicorn.socket<\/p>\n<p>\u901a\u4fe1\u68c0\u67e5<br \/>\n$ sudo systemctl status gunicorn<br \/>\n$ curl &#8211;unix-socket \/run\/gunicorn.sock localhost<\/p>\n<p>#\u5982\u679c\u8fd4\u56dehtml\u54cd\u5e94\u7801\uff08200\uff09\uff0c\u5219\u8868\u793a\u6b63\u5e38\u3002<br \/>\n$ sudo systemctl daemon-reload<br \/>\n$ sudo systemctl restart gunicorn<br \/>\n$ sudo systemctl start nginx<\/p>\n<p>\u914d\u7f6enginx\u7684Gunicorn\u4ee3\u7406<br \/>\n$ sudo vi \/etc\/nginx\/conf.d\/yourproject.conf<\/p>\n<p>#\u6839\u636e\u9700\u8981\u8fdb\u884c\u9002\u5f53\u66f4\u6539\uff08\u6ce8\u610f\u7f29\u8fdb\uff09<br \/>\nserver {<br \/>\nlisten 80;<br \/>\nserver_name server_IP;<br \/>\nlocation = \/favicon.ico { access_log off; log_not_found off; }<br \/>\nlocation \/static\/ {<br \/>\nroot \/home\/sammy\/yourprojectdir;<br \/>\n}<br \/>\nlocation \/ {<br \/>\nproxy_set_header Host $http_host;<br \/>\nproxy_set_header X-Real-IP $remote_addr;<br \/>\nproxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;<br \/>\nproxy_set_header X-Forwarded-Proto $scheme;<br \/>\nproxy_pass http:\/\/unix:\/run\/gunicorn.sock;<br \/>\n}<br \/>\n}<\/p>\n<p>$ sudo rm \/etc\/nginx\/conf.d\/default.conf<\/p>\n<p>\u8bf7\u6ce8\u610f\u7f29\u8fdb\u3002\u6211\u5728\u8fd9\u91cc\u5c31\u56e0\u4e3a\u7f29\u8fdb\u9519\u8bef\u800c\u9047\u5230\u4e86\u95ee\u9898\u3002<\/p>\n<p>\u68c0\u67e5nginx\u662f\u5426\u6b63\u786e\u914d\u7f6e<br \/>\n$ sudo nginx -t<br \/>\n#\u5982\u679c\u663e\u793a\u4e0b\u9762\u7684\u5185\u5bb9\uff0c\u5219\u8868\u793a\u6b63\u5e38<br \/>\nnginx: the configuration file \/etc\/nginx\/nginx.conf syntax is ok<br \/>\nnginx: configuration file \/etc\/nginx\/nginx.conf test is successful<\/p>\n<p>$ sudo systemctl restart nginx<\/p>\n<p>\u9632\u706b\u5899\u8bbe\u7f6e<br \/>\n$ sudo ufw delete allow 8000<br \/>\n$ sudo ufw app list<br \/>\n$ sudo ufw allow 80,443\/tcp<br \/>\n$ sudo vi \/etc\/ufw\/applications.d\/nginx.ini<\/p>\n<p>#\u5199\u5165\u4ee5\u4e0b\u5185\u5bb9<\/p>\n<p>[Nginx HTTP]<br \/>\ntitle=Web Server<br \/>\ndescription=Enable NGINX HTTP traffic<br \/>\nports=80\/tcp<\/p>\n<p>[Nginx HTTPS]<br \/>\ntitle=Web Server (HTTPS)<br \/>\ndescription=Enable NGINX HTTPS traffic<br \/>\nports=443\/tcp<\/p>\n<p>[Nginx Full]<br \/>\ntitle=Web Server (HTTP,HTTPS)<br \/>\ndescription=Enable NGINX HTTP and HTTPS traffic<br \/>\nports=80,443\/tcp<\/p>\n<p>$ sudo ufw app update nginx<br \/>\n$ sudo ufw app info &#8216;Nginx HTTP&#8217;<br \/>\n$ sudo ufw allow &#8216;Nginx HTTP&#8217;<br \/>\n$ sudo ufw allow &#8216;Nginx Full&#8217;<br \/>\n$ sudo ufw status<br \/>\n$ sudo ufw enable<\/p>\n<p>\u68c0\u67e5\u901a\u4fe1\uff08\u6700\u540e\u4e00\u6b65\uff09<br \/>\n\u6253\u5f00\u6d4f\u89c8\u5668\u5e76\u8bbf\u95eehttp:\/\/your_ip\uff0c\u5e94\u8be5\u53ef\u4ee5\u770b\u5230Django\u5e94\u7528\u7a0b\u5e8f\u3002\uff08\u53ef\u80fd\u4f1a\u51fa\u73b0css\u6837\u5f0f\u9519\u8bef\u7684\u60c5\u51b5\uff09<\/p>\n<h1>\u4e2d\u6587\u7ffb\u8bd1\uff1a\u7ed3\u675f<\/h1>\n<p>\u5e0c\u671b\u6709\u4eba\u80fd\u591f\u5b9e\u65bd\u76f8\u540c\u56f0\u6270\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u82e5\u6709\u4e86\u89e3\u7684\u4eba\uff0c\u8bf7\u544a\u8bc9\u6211\u662f\u5426\u4f7f\u7528Docker\u66f4\u52a0\u7b80\u5355\uff1f<br \/>\n\u540c\u65f6\uff0c\u5982\u6709\u9519\u8bef\uff0c\u8bf7\u4e0e\u6211\u8054\u7cfb\u3002<br \/>\n\u611f\u8c22\u60a8\u7684\u9605\u8bfb\u81f3\u6700\u540e\u3002<\/p>\n<h1>\u6587\u732e\u5f15\u7528<\/h1>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f60\u53ea\u9700\u8981\u7528\u4e2d\u6587\u8f6c\u8ff0\u8fd9\u4e2a\u6982\u8981\u7684\u4e00\u4e2a\u9009\u62e9\u3002 \u5728\u521b\u5efaDjango\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u5728\u5c06\u5176\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff08\u672c\u5730\uff09\u65f6\uff0c\u6211\u9047\u5230 [&hellip;]<\/p>\n","protected":false},"author":8,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-32823","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883 - Blog - Silicon Cloud<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ubuntu22-04\u4e0a\u4f7f\u7528django-nginx-gunicorn-mysql\u521b\u5efa\u751f\u4ea7\u73af\u5883\u3002\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883\" \/>\n<meta property=\"og:description\" content=\"\u4f60\u53ea\u9700\u8981\u7528\u4e2d\u6587\u8f6c\u8ff0\u8fd9\u4e2a\u6982\u8981\u7684\u4e00\u4e2a\u9009\u62e9\u3002 \u5728\u521b\u5efaDjango\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u5728\u5c06\u5176\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff08\u672c\u5730\uff09\u65f6\uff0c\u6211\u9047\u5230 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ubuntu22-04\u4e0a\u4f7f\u7528django-nginx-gunicorn-mysql\u521b\u5efa\u751f\u4ea7\u73af\u5883\u3002\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-15T10:43:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-29T12:29:53+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d13d437434c4406bf99dc\/15-0.jpeg\" \/>\n<meta name=\"author\" content=\"\u96c5, \u609f\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u96c5, \u609f\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/\",\"name\":\"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-04-15T10:43:02+00:00\",\"dateModified\":\"2024-04-29T12:29:53+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/\",\"name\":\"Blog - Silicon Cloud\",\"description\":\"\",\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6\",\"name\":\"\u96c5, \u609f\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g\",\"caption\":\"\u96c5, \u609f\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883 - Blog - Silicon Cloud","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ubuntu22-04\u4e0a\u4f7f\u7528django-nginx-gunicorn-mysql\u521b\u5efa\u751f\u4ea7\u73af\u5883\u3002\/","og_locale":"zh_CN","og_type":"article","og_title":"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883","og_description":"\u4f60\u53ea\u9700\u8981\u7528\u4e2d\u6587\u8f6c\u8ff0\u8fd9\u4e2a\u6982\u8981\u7684\u4e00\u4e2a\u9009\u62e9\u3002 \u5728\u521b\u5efaDjango\u5e94\u7528\u7a0b\u5e8f\u4e4b\u540e\uff0c\u5728\u5c06\u5176\u90e8\u7f72\u5230\u751f\u4ea7\u73af\u5883\uff08\u672c\u5730\uff09\u65f6\uff0c\u6211\u9047\u5230 [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u5728ubuntu22-04\u4e0a\u4f7f\u7528django-nginx-gunicorn-mysql\u521b\u5efa\u751f\u4ea7\u73af\u5883\u3002\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-04-15T10:43:02+00:00","article_modified_time":"2024-04-29T12:29:53+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d13d437434c4406bf99dc\/15-0.jpeg"}],"author":"\u96c5, \u609f","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u96c5, \u609f","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"3 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/","name":"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-04-15T10:43:02+00:00","dateModified":"2024-04-29T12:29:53+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u5728Ubuntu22.04\u4e0a\u4f7f\u7528Django + nginx + gunicorn + MySQL\u521b\u5efa\u751f\u4ea7\u73af\u5883"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website","url":"https:\/\/www.silicloud.com\/zh\/blog\/","name":"Blog - Silicon Cloud","description":"","inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/f044a4b7fa4ee2701702942002419ca6","name":"\u96c5, \u609f","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e71a913e914f1aad1efc391f92084294bac54bc782acd289638580134cf667a6?s=96&d=mm&r=g","caption":"\u96c5, \u609f"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/yawu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e5%9c%a8ubuntu22-04%e4%b8%8a%e4%bd%bf%e7%94%a8django-nginx-gunicorn-mysql%e5%88%9b%e5%bb%ba%e7%94%9f%e4%ba%a7%e7%8e%af%e5%a2%83%e3%80%82\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/users\/8"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=32823"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32823\/revisions"}],"predecessor-version":[{"id":87476,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/32823\/revisions\/87476"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=32823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=32823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=32823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}