{"id":49345,"date":"2023-08-05T15:01:22","date_gmt":"2023-08-16T00:11:16","guid":{"rendered":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/"},"modified":"2024-04-30T17:08:50","modified_gmt":"2024-04-30T09:08:50","slug":"%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/","title":{"rendered":"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011"},"content":{"rendered":"<h1>\u4f7f\u7528AWS EC2\u4e91\u670d\u52a1\u5668\uff0c\u4ee5\u6700\u7b80\u5355\u7684\u914d\u7f6e\u5c06Nginx\u3001gunicorn\u548cpostgresql\u90e8\u7f72\u3002<\/h1>\n<p>\u5982\u679c\u8981\u7528Python\u521b\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\uff0c\u9996\u9009\u662fDjango\uff0c\u5e76\u4e14\u4f7f\u7528\u6700\u65b0\u76843\u7cfb\u8fdb\u884c\u90e8\u7f72\u3002\u672c\u7bc7\u6587\u7ae0\u7684\u4e3b\u9898\u662f\u8be6\u7ec6\u89e3\u91ca\u5982\u4f55\u8fdb\u884c\u57fa\u672c\u7684AWS\u90e8\u7f72\u3002\u5c3d\u7ba1\u7531\u4e8e\u8be6\u7ec6\u7684\u56fe\u793a\uff0c\u6587\u7ae0\u53ef\u80fd\u4f1a\u663e\u5f97\u6bd4\u8f83\u957f\uff0c\u4f46\u6211\u76f8\u4fe1\u4e00\u65e6\u719f\u6089\u4e86\uff0c\u53ef\u80fd\u53ea\u9700\u5927\u7ea620\u5206\u949f\u5c31\u80fd\u5b8c\u6210\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/2-0.png\" alt=\"image.png\" \/><\/div>\n<p>\u5728\u4e2d\u6587\u4e2d\u91cd\u8ff0\u4ee5\u4e0b\u5185\u5bb9\uff08\u53ea\u9700\u8981\u4e00\u79cd\u65b9\u6848\uff09\uff1a<br \/>\n\u5728Django\u7684\u6559\u7a0b\u4e2d\uff0c\u6211\u8ba4\u4e3a\u901a\u5e38\u4f1a\u628a\u5e94\u7528\u90e8\u7f72\u5230Heroku\u7684\u514d\u8d39\u7248\u4e0a\uff0c<br \/>\n\u4f46\u65e0\u8bba\u662f\u5bf9\u4e8e\u5de5\u4f5c\u8fd8\u662f\u5236\u4f5c\u4e2a\u4eba\u4f5c\u54c1\u96c6\u6765\u8bf4\uff0c\u4f7f\u7528Heroku\u5e76\u4e0d\u7406\u60f3\u3002<\/p>\n<div>\u66f4\u65b0\uff1aHeroku \u73b0\u5728\u5df2\u7ecf\u5b9e\u65bd\u6536\u8d39\u5236\u5ea6\u3002\u867d\u7136\u8fd8\u6709\u5176\u4ed6\u53ef\u4ee5\u514d\u8d39\u90e8\u7f72\u7684\u670d\u52a1\uff08\u5982 Fly.io\uff09\uff0c\u4f46\u76ee\u524d\u6765\u8bf4\uff0c\u719f\u7ec3\u4f7f\u7528 AWS \u8fdb\u884c\u90e8\u7f72\u4f1a\u66f4\u6709\u4f18\u52bf\u3002<\/div>\n<h2>\u2716\ufe0f \u4f7f\u7528Heroku\u8fdb\u884c\u90e8\u7f72\u7684\u4e0d\u5229\u4e4b\u5904<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u7121\u6599\u3060\u3068\u30a2\u30af\u30bb\u30b9\u306b\u6642\u9593\u304b\u304b\u308b(\u3057\u3070\u3089\u304f\u30a2\u30af\u30bb\u30b9\u3055\u308c\u3066\u3044\u306a\u3044\u5834\u5408)<\/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\">heroku\u30c7\u30d7\u30ed\u30a4\u3060\u3068\u30dd\u30fc\u30c8\u30d5\u30a9\u30ea\u30aa\u306b\u4f7f\u3046\u306b\u306f\u5c11\u3057\u624b\u629c\u304d\u611f\u3092\u6301\u3064\u63a1\u7528\u8005\u5897\u3048\u305f<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u65e5\u672c\u306e\u4f01\u696d\u3067\u4f7f\u3046\u306a\u3089\u5927\u4f53AWS<\/ul>\n<h2>\u2b55\ufe0f Heroku\u90e8\u7f72\u7684\u4f18\u70b9<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u7121\u6599\u3067\u7c21\u5358\u3002\u521d\u5fc3\u8005\u306b\u512a\u3057\u3044<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u60c5\u5831\u3082\u591a\u3044<\/ul>\n<h2>\u2716\ufe0f AWS\u90e8\u7f72\u7684\u7f3a\u70b9<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">AWS\u306f\uff11\u5e74\u9593\u306e\u7121\u6599\u671f\u9593\u904e\u304e\u3066\u3057\u307e\u3046\u3068\u3001\u6bce\u6708\u304c\u30a2\u30af\u30bb\u30b9\u306a\u304f\u3066\u3082\u5e97\u3067\u300c\u3046\u306a\u91cd\u300d\u98df\u3048\u308b\u304f\u3089\u3044\u306f\u304a\u91d1\u304b\u304b\u308b<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u5c11\u3057\u8907\u96d1\u3002\u30a4\u30f3\u30d5\u30e9\u5468\u308a\u306e\u77e5\u8b58\u304c\u3044\u308b<\/ul>\n<h2>\u2b55\ufe0f AWS\u90e8\u7f72\u7684\u4f18\u70b9<\/h2>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">\u4f7f\u3063\u3066\u3044\u306a\u3044\u4f1a\u793e\u306e\u65b9\u304c\u5c11\u306a\u3044\u306e\u3067\u5c31\u8077\u30fb\u8ee2\u8077\u30fb\u30d5\u30ea\u30fc\u30e9\u30f3\u30b9\u3044\u305a\u308c\u3082\u30ad\u30e3\u30ea\u30a2\u6709\u5229\u306b\u306a\u308b\u306f\u305a<\/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\">\u30a4\u30f3\u30d5\u30e9\u5468\u308a\u306e\u77e5\u8b58\u3064\u304f<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u9ad8\u5358\u4fa1\u306b\u306a\u308a\u3084\u3059\u3044DevOps\u30a8\u30f3\u30b8\u30cb\u30a2\u306e\u57fa\u790e\u5b66\u3079\u308b<\/ul>\n<p>\u56e0\u6b64\uff0c\u6211\u5c07\u5c08\u6ce8\u65bc\u5982\u4f55\u5728AWS\u4e0a\u5feb\u901f\u4e14\u4ed4\u7d30\u5730\u90e8\u7f72\uff0c\u4e26\u5728\u672c\u6587\u4e2d\u52a0\u4ee5\u8a18\u8f09\u3002<\/p>\n<p>\u5bf9\u4e8e\u90a3\u4e9b\u9700\u8981\u517c\u987e\u52c9\u5f3a\u548c\u7ec3\u4e60\u76ee\u7684\u7684\u4eba\uff0c\u6211\u4e5f\u4f1a\u63d0\u4f9b\u89e3\u9664\u5df2\u90e8\u7f72\u5e94\u7528\u7684\u65b9\u6cd5\uff0c\u4ee5\u786e\u4fdd\u4e0d\u82b1\u8d39\u4efb\u4f55\u8d39\u7528\uff0c\u8ba9\u60a8\u653e\u5fc3\u3002<\/p>\n<h1>\u73af\u5883<\/h1>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">Mac<\/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\">Python 3.8<\/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\">Django 3.1.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\">PostgreSQL 12.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\">Nginx 1.18.0<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">gunicorn 20.0.4<\/ul>\n<h1>\u6b65\u9aa4<\/h1>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u6211\u5728Github\u4e0a\u521b\u5efa\u4e00\u4e2a\u79c1\u6709\u4ed3\u5e93<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728\u672c\u5730\u7528Django\u521b\u5efa\u4e00\u4e2a\u6700\u7b80\u5355\u7684\u5e94\u7528\u7a0b\u5e8f<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8fdb\u884c\u63a8\u9001<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u521b\u5efaEC2\u5b9e\u4f8b<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4eceAWS\u4e2d\u83b7\u53d6Git\u4ee3\u7801\u5e76\u90e8\u7f72<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u5b8c\u6210\u540e\u62c6\u9664\u5b83<\/ol>\n<p>\u5982\u679c\u4f60\u662f\u4e00\u4e2a\u521d\u5b66\u8005\uff0c\u6211\u8ba4\u4e3a\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u5728AWS\u4e0a\u7ec3\u4e60\u90e8\u7f72\u3002\u4e00\u65e6\u4f60\u6210\u529f\u5b8c\u6210\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u90e8\u7f72\u81ea\u5df1\u7684\u5e94\u7528\u7a0b\u5e8f\u6216\u8005\u7c7b\u4f3c\u8fc7\u53bb\u6587\u7ae0\u7684\u7b80\u5355\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>&nbsp;<\/p>\n<h1>\u5728Github\u4e0a\u521b\u5efa\u4e00\u4e2a\u5b58\u50a8\u5e93\u3002<\/h1>\n<p>\u6211\u4f1a\u786e\u4fdd\u8fd9\u7bc7\u6587\u7ae0\u53ef\u4ee5\u5728\u516c\u5171\u4ed3\u5e93\u4e2d\u516c\u5f00\u3002<\/p>\n<p>\u7136\u800c\uff0c\u5bf9\u4e8e\u521d\u5b66\u8005\u6765\u8bf4\uff0c\u6700\u597d\u5728\u79c1\u4eba\u4ed3\u5e93\u4e2d\u8fdb\u884c\u64cd\u4f5c\uff0c\u4ee5\u786e\u4fdd\u5b89\u5168\u6027\uff0c\u56e0\u4e3a\u53ef\u80fd\u4f1a\u4e0d\u5c0f\u5fc3\u5c06\u5371\u9669\u7684\u5185\u5bb9\u516c\u5f00\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/24-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 17.05.32.png\" \/><\/div>\n<p>\u5f53\u4f60\u5728add .gitignore\u65f6\u52fe\u9009\u4e86Python\u9009\u9879\uff0c\u5e76\u9009\u62e9\u4e86\u4e0d\u516c\u5f00\u7684\u6587\u4ef6\uff0c\u5b83\u4f1a\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u6392\u9664\u8fd9\u4e9b\u6587\u4ef6\u7684\u914d\u7f6e\uff0c\u8fd9\u6837\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<h2>\u4eceGitHub\u8fdb\u884c\u514b\u9686<\/h2>\n<pre class=\"post-pre\"><code>$ mkdir django\r\n$ cd django\r\n<\/code><\/pre>\n<p>\u8bf7\u5728 Mac \u4e0a\u8bbe\u7f6e SSH\u3002\u6709\u5f88\u591a\u6587\u7ae0\u53ef\u4ee5\u627e\u5230\uff0c\u6211\u4e5f\u4f1a\u9644\u4e0a\u6211\u7684\u6587\u7ae0\u3002\u867d\u7136\u5199\u7684\u662f Ubuntu\uff0c\u4f46\u662f\u5728 Mac \u4e0a\u4e5f\u53ef\u4ee5\u7528\u76f8\u540c\u7684\u65b9\u6cd5\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u5bf9\u4e8e\u5df2\u7ecf\u8bbe\u7f6e\u4e86 SSH \u7684\u4eba\u6765\u8bf4\uff0c\u53ef\u4ee5\u5c06 HTTPS \u7684 URL \u590d\u5236\u5e76\u514b\u9686\u5230\u672c\u5730\u3002<\/p>\n<pre class=\"post-pre\"><code>$ git clone \u3053\u3053\u306b\u30b3\u30d4\u30fc\u3057\u305fURL\r\n$ cd django-aws\r\n<\/code><\/pre>\n<p>\u5728\u6211\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4f7f\u7528django-aws\u521b\u5efa\u4e86\u4e00\u4e2a\u4ee3\u7801\u5e93\u3002<\/p>\n<h1>\u7528Django\u5728\u672c\u5730\u521b\u5efa\u6700\u57fa\u672c\u7684\u5e94\u7528\u7a0b\u5e8f<\/h1>\n<p>\u8fd9\u6b21\u6211\u4eec\u5c06\u4f7f\u7528pipenv\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<br \/>\n\u53ea\u8981\u80fd\u5728\u6211\u7684\u7535\u8111\u4e0a\u6b63\u5e38\u8fd0\u884c\uff0c\u4f60\u53ef\u4ee5\u9009\u62e9\u5728\u672c\u5730\u521b\u5efa\u4efb\u4f55\u865a\u62df\u73af\u5883\uff01<\/p>\n<p>\u6211\u4ee5\u524d\u5199\u4e86\u4e00\u7bc7Pipenv\u73af\u5883\u642d\u5efa\u7684\u6587\u7ae0\uff0c\u987a\u4fbf\u8d34\u51fa\u6765\u3002\u8fd9\u6b21\u8981\u7528\u7684\u662fMac&#8230;<\/p>\n<p>\u7531\u4e8e\u6211\u7684Anaconda\u592a\u91cd\u4e86\uff0c\u6211\u51b3\u5b9a\u4f7f\u7528Pipenv\u8fdb\u884c\u3010Windows10 Python\u73af\u5883\u642d\u5efa\u3011\u3002<\/p>\n<p>\u5982\u679c\u5c1a\u672a\u5b89\u88c5pipenv\uff0c\u8bf7\u5b89\u88c5\u5e76\u6307\u5b9a\u7248\u672c\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pip install pipenv\r\n$ pipenv --python 3.8.7\r\n<\/code><\/pre>\n<p>\u5c06Django\u548c\u7528\u4e8e\u8bfb\u53d6.env\u6587\u4ef6\u7684\u7ec4\u4ef6\u4ee5\u53ca\u8bbf\u95ee\u6570\u636e\u5e93\u6240\u9700\u7684\u7ec4\u4ef6\u4e00\u5e76\u6dfb\u52a0\u8fdb\u6765\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pipenv install django\r\n$ pipenv install django-environ\r\n$ pipenv install dj-database-url\r\n<\/code><\/pre>\n<p>\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\uff0c\u5e76\u521b\u5efa\u4e00\u4e2a\u540d\u4e3atestapp\u7684\u9879\u76ee\u548c\u4e00\u4e2a\u540d\u4e3aapp\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<br \/>\n\u8fd0\u884cstartproject testapp .\u547d\u4ee4\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u9879\u76ee\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pipenv shell\r\n$ django-admin startproject testapp .\r\n$ django-admin startapp app\r\n<\/code><\/pre>\n<p>\u5728\u6709manage.py\u6587\u4ef6\u7684\u4f4d\u7f6e\u4e0a\uff0c\u8f93\u5165\u547d\u4ee4\u5e76\u5c1d\u8bd5\u542f\u52a8\u672c\u5730\u670d\u52a1\u5668\u3002<\/p>\n<pre class=\"post-pre\"><code>$ python manage.py runserver\r\n<\/code><\/pre>\n<blockquote><p>http:\/\/127.0.0.1:8000\/ \u53ef\u4ee5\u88ab\u7b80\u5316\u4e3a &#8220;\u672c\u5730\u4e3b\u673a\u5730\u5740\u4e3a 8000 \u7aef\u53e3&#8221;\u3002<\/p><\/blockquote>\n<p>\u5982\u679c\u706b\u7bad\u8d77\u98de\u4e86\u5c31\u53ef\u4ee5<\/p>\n<h1>\u5f53\u5728.env\u6587\u4ef6\u4e2d\u53d1\u5e03\u65f6\uff0c\u4ec5\u7f16\u5199\u5371\u9669\u6570\u636e\u3002<\/h1>\n<p>\u5728manage.py\u6240\u5728\u7684\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a.env\u7684\u6587\u4ef6\u3002<\/p>\n<p>\u5c06 settings.py \u6587\u4ef6\u4e2d\u4ee5\u4e0b\u4e09\u4e2a\u5185\u5bb9\u5199\u5165 .env \u6587\u4ef6\u4e2d\u3002<br \/>\n\u203b\u8bf7\u52ff\u5305\u542b\u65e0\u7528\u7684\u7a7a\u683c\u3001\u9017\u53f7\u6216\u5f15\u53f7\u3002<\/p>\n<pre class=\"post-pre\"><code>SECRET_KEY=1234567890sdogdmsmoa@:dmmgsv94kmvaso(9l\r\nDEBUG=False\r\nDATABASE_URL=sqlite:\/\/\/db.sqlite3\r\n<\/code><\/pre>\n<p>\u5c06\u76f8\u5173\u5185\u5bb9\u4ece.env\u6587\u4ef6\u4e2d\u8bfb\u53d6\u5e76\u8fdb\u884c\u53d8\u66f4\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"kn\">import<\/span> <span class=\"n\">environ<\/span>\r\n<span class=\"kn\">import<\/span> <span class=\"n\">os<\/span>\r\n<span class=\"p\">.<\/span>\r\n<span class=\"p\">.<\/span>\r\n\r\n\r\n<span class=\"n\">env<\/span> <span class=\"o\">=<\/span> <span class=\"n\">environ<\/span><span class=\"p\">.<\/span><span class=\"nc\">Env<\/span><span class=\"p\">()<\/span>\r\n<span class=\"n\">env<\/span><span class=\"p\">.<\/span><span class=\"nf\">read_env<\/span><span class=\"p\">(<\/span><span class=\"n\">os<\/span><span class=\"p\">.<\/span><span class=\"n\">path<\/span><span class=\"p\">.<\/span><span class=\"nf\">join<\/span><span class=\"p\">(<\/span><span class=\"n\">BASE_DIR<\/span><span class=\"p\">,<\/span> <span class=\"sh\">'<\/span><span class=\"s\">.env<\/span><span class=\"sh\">'<\/span><span class=\"p\">))<\/span>\r\n<span class=\"n\">SECRET_KEY<\/span> <span class=\"o\">=<\/span> <span class=\"nf\">env<\/span><span class=\"p\">(<\/span><span class=\"sh\">'<\/span><span class=\"s\">SECRET_KEY<\/span><span class=\"sh\">'<\/span><span class=\"p\">)<\/span>\r\n<span class=\"n\">DEBUG<\/span> <span class=\"o\">=<\/span> <span class=\"nf\">env<\/span><span class=\"p\">(<\/span><span class=\"sh\">'<\/span><span class=\"s\">DEBUG<\/span><span class=\"sh\">'<\/span><span class=\"p\">)<\/span>\r\n\r\n<span class=\"n\">INSTALLED_APPS<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span>\r\n\r\n    <span class=\"sh\">'<\/span><span class=\"s\">app.apps.AppConfig<\/span><span class=\"sh\">'<\/span><span class=\"p\">,<\/span> <span class=\"c1\"># \u8ffd\u52a0\r\n<\/span><span class=\"p\">]<\/span>\r\n\r\n<span class=\"p\">.<\/span>\r\n<span class=\"p\">.<\/span>\r\n<span class=\"p\">.<\/span>\r\n\r\n<span class=\"n\">DATABASES<\/span> <span class=\"o\">=<\/span> <span class=\"p\">{<\/span>\r\n    <span class=\"sh\">'<\/span><span class=\"s\">default<\/span><span class=\"sh\">'<\/span><span class=\"p\">:<\/span> <span class=\"n\">env<\/span><span class=\"p\">.<\/span><span class=\"nf\">db<\/span><span class=\"p\">(),<\/span>\r\n<span class=\"p\">}<\/span>\r\n<\/code><\/pre>\n<p>\u56e0\u4e3a\u4f60\u5728createapp\u4e2d\u6307\u5b9a\u4e86app\uff0c\u6240\u4ee5&#8217;app.apps.AppConfig&#8217;\u4f1a\u53d8\u6210\u8fd9\u6837\u3002\u5982\u679c\u4f60\u5728djangoapp\u4e2d\u4f7f\u7528createapp\uff0c\u90a3\u4e48\u5c31\u4f1a\u53d8\u6210&#8217;djangoapp.apps.DjangoappConfig&#8217;\u3002<\/p>\n<h2>\u786e\u8ba4.gitignore<\/h2>\n<p>\u53ea\u8981\u6309\u7167\u6b65\u9aa4\u6765\u505a\uff0c\u6211\u8ba4\u4e3a\u5c31\u6ca1\u6709\u95ee\u9898\uff0c\u4f46\u662f\u5982\u679c\u4f7f\u7528\u4e86\u5176\u4ed6\u65b9\u6cd5\uff0c\u90a3\u4e48\u8bf7\u67e5\u770b\u4ee5\u4e0b\u7684.gitignore\u6587\u4ef6\u4e2d\u7684.env\u63cf\u8ff0\u3002<\/p>\n<pre class=\"post-pre\"><code>.env\r\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u6837\u505a\uff0c\u53ef\u4ee5\u8ba9\u73af\u5883\u53d8\u91cf\u4e0d\u88ab\u52a0\u5165\u5230 GitHub \u4ed3\u5e93\u4e2d\u3002<\/p>\n<h1>\u4e3a\u4e86\u5c06\u6240\u9700\u7684\u5e93\u5b89\u88c5\u5230\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u521b\u5efa\u4e00\u4e2a requirements.txt \u6587\u4ef6\u3002<\/h1>\n<p>\u6211\u4f1a\u5bfc\u51fa\u6211\u5728\u672c\u5730\u4f7f\u7528\u7684\u5e93\u3002<br \/>\n\u7a0d\u540e\uff0c\u6211\u4f1a\u5c06\u5176\u5b89\u88c5\u5728\u7528\u4e8e\u90e8\u7f72\u5e93\u7684\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<pre class=\"post-pre\"><code>$ pip freeze &gt; requirements-dev.txt\r\n<\/code><\/pre>\n<p>\u73b0\u5728\uff0c\u5df2\u7ecf\u5c06\u5728\u672c\u5730\u8fd0\u884c\u6240\u9700\u7684\u5e93\u5199\u5165\u5230requirements-dev.txt\u6587\u4ef6\u4e2d\u3002<\/p>\n<h2>\u5728EC2\u4e0a\u6dfb\u52a0\u989d\u5916\u4f7f\u7528\u7684\u5e93\uff0c\u9664\u4e86\u672c\u5730\u5e93\u3002<\/h2>\n<p>\u63a5\u4e0b\u6765\uff0c\u521b\u5efarequirements.txt\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>-r requirements-dev.txt\r\ngunicorn\r\npsycopg2\r\n<\/code><\/pre>\n<p>\u5f53\u4f60\u5199\u4e0b\u8fd9\u4e2a\u65f6\uff0c\u53ef\u4ee5\u5728requirements-dev.txt\u4e2d\u5199\u4e0b\u5fc5\u8981\u7684\u5e93\uff0c\u4ee5\u4f7f\u5176\u5728\u5f00\u53d1\u73af\u5883\u4e2d\u8fd0\u884c\uff0c\u5e76\u6dfb\u52a0\u4e00\u79cd\u65b9\u6cd5\u6765\u63cf\u8ff0\u6784\u5efa\u751f\u4ea7\u73af\u5883\u6240\u9700\u7684\u5e93\u3002<\/p>\n<h1>\u521b\u5efa\u4e00\u4e2a\u53ea\u663e\u793a\u7b80\u5355\u5b57\u7b26\u7684\u5e94\u7528\u3002<\/h1>\n<p>\u6dfb\u52a0\u8def\u7531\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"kn\">from<\/span> <span class=\"n\">django.contrib<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">admin<\/span>\r\n<span class=\"kn\">from<\/span> <span class=\"n\">django.urls<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">path<\/span><span class=\"p\">,<\/span> <span class=\"n\">include<\/span> <span class=\"c1\">#\u8ffd\u52a0\r\n<\/span>\r\n\r\n<span class=\"n\">urlpatterns<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span>\r\n    <span class=\"nf\">path<\/span><span class=\"p\">(<\/span><span class=\"sh\">'<\/span><span class=\"s\">admin\/<\/span><span class=\"sh\">'<\/span><span class=\"p\">,<\/span> <span class=\"n\">admin<\/span><span class=\"p\">.<\/span><span class=\"n\">site<\/span><span class=\"p\">.<\/span><span class=\"n\">urls<\/span><span class=\"p\">),<\/span>\r\n    <span class=\"nf\">path<\/span><span class=\"p\">(<\/span><span class=\"sh\">''<\/span><span class=\"p\">,<\/span><span class=\"nf\">include<\/span><span class=\"p\">(<\/span><span class=\"sh\">\"<\/span><span class=\"s\">app.urls<\/span><span class=\"sh\">\"<\/span><span class=\"p\">))<\/span> <span class=\"c1\">#\u8ffd\u52a0\r\n<\/span><span class=\"p\">]<\/span>\r\n<\/code><\/pre>\n<p>\u8bf7\u6dfb\u52a0\u8bfb\u53d6\u5e94\u7528\u7a0b\u5e8f\u4e2d\u7684\u8def\u7531\u7684\u529f\u80fd\u3002<\/p>\n<h3>\u5728app\u76ee\u5f55\u4e2d\u521b\u5efaurls.py\u6587\u4ef6\u3002<\/h3>\n<p>\u5f53\u8bbf\u95eelocalhost:8000\u65f6\uff0c\u4f7f\u7528views.py\u4e2d\u7684index\u65b9\u6cd5\u6765\u521b\u5efa\u9875\u9762\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"kn\">from<\/span> <span class=\"n\">django.urls<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">path<\/span>\r\n<span class=\"kn\">from<\/span> <span class=\"n\">.<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">views<\/span>\r\n\r\n<span class=\"n\">urlpatterns<\/span> <span class=\"o\">=<\/span> <span class=\"p\">[<\/span>\r\n    <span class=\"nf\">path<\/span><span class=\"p\">(<\/span><span class=\"sh\">''<\/span><span class=\"p\">,<\/span> <span class=\"n\">views<\/span><span class=\"p\">.<\/span><span class=\"n\">index<\/span><span class=\"p\">,<\/span> <span class=\"n\">name<\/span><span class=\"o\">=<\/span><span class=\"sh\">'<\/span><span class=\"s\">index<\/span><span class=\"sh\">'<\/span><span class=\"p\">),<\/span>\r\n<span class=\"p\">]<\/span>\r\n<\/code><\/pre>\n<p>\u7f16\u5199\u4e00\u4e2a\u4ec5\u6e32\u67d3\u7eaf\u6587\u5b57HTML\u7684\u5e94\u7528\u7a0b\u5e8f\u7684\u5904\u7406\u8fc7\u7a0b\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"kn\">from<\/span> <span class=\"n\">django.http<\/span> <span class=\"kn\">import<\/span> <span class=\"n\">HttpResponse<\/span>\r\n\r\n\r\n<span class=\"k\">def<\/span> <span class=\"nf\">index<\/span><span class=\"p\">(<\/span><span class=\"n\">request<\/span><span class=\"p\">):<\/span>\r\n    <span class=\"k\">return<\/span> <span class=\"nc\">HttpResponse<\/span><span class=\"p\">(<\/span><span class=\"sh\">'<\/span><span class=\"s\">\u6587\u5b57\u3060\u3051\u30a2\u30d7\u30ea<\/span><span class=\"sh\">'<\/span><span class=\"p\">)<\/span>\r\n<\/code><\/pre>\n<p>\u5f53\u6211\u5c1d\u8bd5\u8bbf\u95ee\u65f6<\/p>\n<blockquote><p>http:\/\/127.0.0.1:8000\/ \u53ef\u4ee5\u91cd\u65b0\u8868\u8fbe\u4e3a\uff1a<\/p>\n<p>http:\/\/127.0.0.1:8000\/<\/p><\/blockquote>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/77-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.32.38.png\" \/><\/div>\n<p>\u6211\u505a\u597d\u4e86\u53ea\u663e\u793a\u6587\u5b57\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5c31\u50cf\u8fd9\u6837\uff08\u7b11\uff09\u3002<\/p>\n<h1>\u5c06\u4ee3\u7801\u63a8\u9001\u5230 Github\u3002<\/h1>\n<p>\u53ea\u8981\u80fd\u628a\u4ee3\u7801\u653e\u5728EC2\u521b\u5efa\u7684\u5730\u65b9\uff0c\u9664\u4e86git\u8fd8\u6709\u5176\u4ed6\u65b9\u6cd5\uff0c\u4f46\u6700\u65b9\u4fbf\u7684\u662fgit\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5c06\u4ee3\u7801\u63a8\u9001\u5230GitHub\u4e0a<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5728EC2\u4e0a\u62c9\u53d6\u4ee3\u7801\u4ee5\u83b7\u53d6<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u521b\u5efa\u4e00\u4e2a\u751f\u4ea7\u73af\u5883\uff0c\u4ee5\u4fbf\u8fd0\u884c\u6211\u4eec\u8fd9\u6b21\u5f00\u53d1\u7684\u5e94\u7528\u7a0b\u5e8f<\/ol>\n<p>\u90a3\u4e48\uff0c\u5c06\u5176\u63a8\u9001\u5230\u5b58\u50a8\u5e93\u4e2d\u3002<br \/>\n\u203b \u5df2\u7ecf\u6309\u7167\u4e4b\u524d\u7684\u6b65\u9aa4\u8fdb\u884c\u8bbe\u7f6e\uff0c\u4f46\u4e3a\u4e86\u4fdd\u9669\u8d77\u89c1\uff0c\u4e0d\u8981\u5c06.env\u6587\u4ef6\u63a8\u9001\u3002<\/p>\n<pre class=\"post-pre\"><code>$ git add .\r\n$ git commit -m \"\u6587\u5b57\u3060\u3051\u30a2\u30d7\u30ea\"\r\n$ git push\r\n<\/code><\/pre>\n<h1>7. \u5728AWS EC2\u4e0a\u90e8\u7f72\u64cd\u4f5c<\/h1>\n<p>\u5728\u521b\u5efa\u8d26\u53f7\u65f6\uff0c\u6211\u4eec\u5c06\u7701\u7565IAM\u8bbe\u7f6e\u7b49\u6b65\u9aa4\u3002<\/p>\n<h2>\u5728AWS\u63a7\u5236\u53f0\u4e0a\u8fdb\u884c\u64cd\u4f5c\u3002<\/h2>\n<p>\u8bf7\u641c\u7d22\u5e76\u9009\u62e9EC2\u3002<br \/>\n*\u7531\u4e8eAWS\u7684UI\u7ecf\u5e38\u66f4\u6539\uff0c\u5982\u679c\u4e0e\u56fe\u50cf\u4e0d\u540c\uff0c\u8bf7\u9009\u62e9\u76f8\u4f3c\u7684\u9009\u9879\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/88-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.41.29.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/89-1.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.44.13.png\" \/><\/div>\n<p>\u8fd9\u6b21\u6211\u5c06\u4f7f\u7528Ubuntu\u64cd\u4f5c\u7cfb\u7edf\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/91-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.47.14.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/92-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.49.51.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/93-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.51.28.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/94-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.52.47.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/95-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 19.54.06.png\" \/><\/div>\n<p>\u8bf7\u5c06\u5b89\u5168\u7ec4\u66f4\u6539\u4e3a\u6613\u61c2\u7684\u201cdjango\u201d\uff0c\u7136\u540e\u70b9\u51fb\u786e\u8ba4\u548c\u521b\u5efa\u3002<br \/>\n\u8fd9\u53ea\u662f\u4e3a\u4e86\u533a\u5206\u6211\u5728\u8fd9\u6b21\u4f7f\u7528\u65f6\u9009\u62e9\u7684\u5b89\u5168\u7ec4\uff0c\u6240\u4ee5\u4efb\u4f55\u90fd\u53ef\u4ee5\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/97-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 20.01.54.png\" \/><\/div>\n<p>\u60a8\u7684\u5b89\u5168\u53d7\u5230\u5a01\u80c1\u4e86\u5462\u3002<br \/>\n\u672c\u6765\u5e94\u8be5\u5c06 SSH \u8bbe\u7f6e\u4e3a\u53ea\u80fd\u8ba9\u81ea\u5df1\u5bb6\u548c\u5de5\u4f5c\u573a\u6240\u7684 IP \u8bbf\u95ee\uff0c\u4f46\u662f IP \u4f1a\u7ecf\u5e38\u53d8\u5316\uff0c\u800c\u4e14\u5982\u679c\u5728\u5bb6\u4ee5\u5916\u7684\u5730\u65b9\u5de5\u4f5c\u5c31\u65e0\u6cd5\u8bbf\u95ee\uff0c\u975e\u5e38\u9ebb\u70e6\u3002<br \/>\n\u8fd9\u53ea\u662f\u7ec3\u4e60\uff0c\u4e0d\u7528\u7406\u4f1a\u90a3\u4e9b\u5a01\u80c1\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/99-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 20.04.12.png\" \/><\/div>\n<p>\u9019\u6b21\u6211\u5011\u547d\u540d\u70badjangoapp\uff0c\u4e0b\u8f09\u5bc6\u9470\u5c0d\u3002\u53ea\u8981\u6211\u81ea\u5df1\u77e5\u9053\u5c31\u53ef\u4ee5\uff0c\u8acb\u96a8\u610f\u3002\u6ce8\u610f\uff1a<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4e3a\u4e86\u4e0d\u4e22\u5931\u5bc6\u94a5\u5bf9\uff0c\u8bf7\u6ce8\u610f\u4e0d\u8981\u4e22\u5931\u5b83\u4eec\u3002\u5426\u5219\u4f60\u5c06\u65e0\u6cd5\u8bbf\u95ee\u3002<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u7edd\u5bf9\u4e0d\u80fd\u5c06\u6b64\u5bc6\u94a5\u516c\u5f00\u5728\u4e92\u8054\u7f51\u4e0a\uff01<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u7edd\u5bf9\u4e0d\u80fd\u5c06\u6b64\u5bc6\u94a5\u653e\u5165\u9700\u8981\u901a\u8fc7GitHub\u8fdb\u884c\u63a8\u9001\u7684\u76ee\u5f55\u4e2d\uff01<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u5426\u5219\u4f1a\u51fa\u73b0\u5f88\u9ebb\u70e6\u7684\u60c5\u51b5?\u3002<\/ol>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/102-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 20.06.06.png\" \/><\/div>\n<p>\u8bf7\u5728\u4e3b\u6587\u4ef6\u5939\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3aaws_key\u7684\u6587\u4ef6\u5939\uff0c\u5e76\u5c06\u4e0b\u8f7d\u7684\u5bc6\u94a5\u79fb\u52a8\u5230\u8be5\u6587\u4ef6\u5939\u4e2d\uff0c\u4ee5\u4fbf\u66f4\u6613\u7406\u89e3\u3002\u7136\u540e\u70b9\u51fb&#8221;\u521b\u5efa\u5b9e\u4f8b&#8221;\u3002<\/p>\n<p>\u6309\u4e0b\u300c\u663e\u793a\u5b9e\u4f8b\u300d\u5373\u53ef\u8fd4\u56de\u4ee5\u4e0b\u753b\u9762\u3002<br \/>\n\u4e00\u65e6\u5f00\u59cb\u6267\u884c\uff0c\u5219\u7ee7\u7eed\u8fdb\u884c\u4e0b\u4e00\u6b65\u9aa4\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/105-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-22 20.11.30.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/106-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-25 17.57.34.png\" \/><\/div>\n<h2>\u63a7\u5236\u53f0\u64cd\u4f5c<\/h2>\n<p>\u8ba9\u6211\u4eec\u5c1d\u8bd5\u5728\u7ec8\u7aef\u4e0a\u8fde\u63a5\uff0c\u56e0\u4e3a\u5728&#8221;SSH\u5ba2\u6237\u7aef&#8221;\u9009\u9879\u5361\u4e0a\u6709\u8fde\u63a5\u65b9\u6cd5\u7684\u8bf4\u660e\u3002<\/p>\n<p>\u6211\u5728\u6211\u7684\u7535\u8111\u4e0a\uff0c\u8fdb\u5165\u4fdd\u5b58\u5bc6\u94a5\u6587\u4ef6\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165\u6240\u5199\u7684\u547d\u4ee4\u3002\u5f88\u53ef\u80fd\u547d\u4ee4\u662f\u7c7b\u4f3c\u8fd9\u6837\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code>$ chmod 400 \u3053\u3053\u304c\u9375\u306e\u540d\u524d\r\n$ ssh -i \"\u9375\u540d\" ubuntu@ec2-13-111-111-111.ap-northeast-1.compute.amazonaws.com\r\n<\/code><\/pre>\n<p>\u6211\u8ba4\u4e3a2-13-111-111-111\u4e2d\u7684\u6570\u5b57\u662f\u4e0d\u540c\u7684\u3002<\/p>\n<p>\u5c06\u300c\u4f8b:\u300d\u4e0a\u9762\u7684\u5185\u5bb9\u539f\u5c01\u4e0d\u52a8\u5730\u590d\u5236\u7c98\u8d34\u5230\u63a7\u5236\u53f0\u3002<\/p>\n<p>\u63a5\u7740\u53d1\u751f\u4e86\u4ec0\u4e48<\/p>\n<p>\u56e0\u4e3a\u88ab\u8be2\u95ee\u662f\u5426\u786e\u5b9a\u8981\u7ee7\u7eed\u8fde\u63a5\uff08\u662f\/\u5426\/\u6307\u7eb9\uff09\uff0c\u6240\u4ee5\u56de\u7b54\u662f\u5e76\u8f93\u5165\u3002<\/p>\n<p>\u6211\u5df2\u7ecf\u5c06\u5176\u5b89\u88c5\u8fdb\u4e86EC2\uff08\u64cd\u4f5c\u7cfb\u7edf\u662fUbuntu\uff09\u3002<\/p>\n<h1>8. \u5728\u6211\u521b\u5efa\u7684Ubuntu\u7684EC2\u5b9e\u4f8b\u4e0a\u8fdb\u884c\u64cd\u4f5c\u3002<\/h1>\n<p>\u867d\u7136\u8bf4\u662f EC2\uff0c\u4f46\u5b83\u53ea\u662f\u4e00\u4e2a Linux\u7684\u4e2a\u4eba\u7535\u8111\uff0c\u6240\u4ee5\u4e0e\u5728 Mac\u4e0a\u5efa\u7acb\u73af\u5883\u7684\u8fc7\u7a0b\u5e76\u6ca1\u6709\u592a\u5927\u533a\u522b\uff0c\u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u8fdb\u884c\u3002<\/p>\n<p>Ubuntu\u7684\u8f6f\u4ef6\u5305\u7ba1\u7406\u5668\u662fapt-get\u3002\u53ef\u80fd\u4f1a\u6709\u65e7\u7248\u672c\uff0c\u5efa\u8bae\u66f4\u65b0\u4e00\u4e0b\u3002<br \/>\n\u203b \u7c7b\u4f3c\u4e8eMac\u4e0a\u7684brew\u3002<\/p>\n<pre class=\"post-pre\"><code># cd \u3067\u4e00\u5fdchome\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3067\u884c\u3046\u3053\u3068\u306b\u3059\u308b\r\n$ cd\r\n$ sudo apt-get update\r\n<\/code><\/pre>\n<p>\u5982\u679c\u6709\u4eba\u5173\u6ce8\u5b89\u5168\u95ee\u9898\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a\u65b0\u7528\u6237\u5e76\u6388\u4e88\u6743\u9650\u7b49\u3002\u8fd9\u91cc\u6211\u4eec\u8df3\u8fc7\u3002<\/p>\n<p>\u6211\u5c06\u4e0b\u8f7d\u4f7f\u7528\u7684\u4e00\u6574\u5957\u4e1c\u897f\u3002<br \/>\n\u6211\u5c06\u5b89\u88c5Python\u548cPostgreSQL\u6570\u636e\u5e93\uff0c\u4ee5\u53ca\u670d\u52a1\u5668\u8f6f\u4ef6nginx\u548c\u5176\u4ed6\u5fc5\u8981\u7684\u5e93\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sudo apt-get install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx\r\n<\/code><\/pre>\n<p>\u5982\u679c\u51fa\u73b0[Y\/n]\uff0c\u8bf7\u8f93\u5165Y\u3002<\/p>\n<h2>PostgreSQL\u6570\u636e\u5e93\u914d\u7f6e<\/h2>\n<p>\u6211\u5011\u5c07\u8a2d\u7f6ePosgres\u6578\u64da\u5eab\u3002<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u521b\u5efa\u6570\u636e\u5e93<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u521b\u5efa\u7528\u6237\uff08\u8bf7\u9002\u65f6\u66f4\u6539\u5bc6\u7801\uff09<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8bbe\u7f6e\u6570\u636e\u5e93\u7684\u5b57\u7b26\u7f16\u7801\u4e3aUTF8<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u8bbe\u7f6e\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff08\u6682\u65f6\u53ef\u4ee5\u590d\u5236\u7c98\u8d34\uff09<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u4ee5\u65e5\u672c\u65f6\u95f4\u4e3a\u51c6<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u5c06\u6240\u6709\u6570\u636e\u5e93\u6743\u9650\u6388\u4e88\u5df2\u521b\u5efa\u7684\u7528\u6237<\/ol>\n<pre class=\"post-pre\"><code>$ sudo -u postgres psql\r\npostgres=# CREATE DATABASE djangodb;\r\npostgres=# CREATE USER django WITH PASSWORD 'testPassword1';\r\npostgres=# ALTER ROLE django SET client_encoding TO 'utf8';\r\npostgres=# ALTER ROLE django SET default_transaction_isolation TO 'read committed';\r\npostgres=# ALTER ROLE django SET timezone TO 'UTC+9';\r\npostgres=# GRANT ALL PRIVILEGES ON DATABASE djangodb TO django;\r\npostgres=# \\q\r\n<\/code><\/pre>\n<p>\u987a\u4fbf\u8bf4\u4e00\u4e0b\uff0c\u5728Mac\u4e0a\u8f93\u5165\u53cd\u659c\u6760\u7684\u65b9\u6cd5\u662f\u6309\u4f4fOption\u952e\u7136\u540e\u6309\u00a5\u952e\u3002<\/p>\n<h2>\u53ef\u4ee5\u5c06\u5176\u653e\u5165\u865a\u62df\u73af\u5883\u4e2d\u3002<\/h2>\n<p>\u6211\u4eec\u5728\u8fd9\u91cc\u4f7f\u7528virtualenv\u4f5c\u4e3a\u865a\u62df\u73af\u5883\u3002\u8bf7\u8fdb\u884c\u66f4\u65b0\u548c\u5b89\u88c5\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sudo -H pip3 install --upgrade pip\r\n$ sudo -H pip3 install virtualenv\r\n<\/code><\/pre>\n<p>\u73b0\u5728, \u6211\u4eec\u4f1a\u521b\u5efa\u4e00\u4e2a\u865a\u62df\u73af\u5883\u5e76\u8fdb\u5165\u5176\u4e2d\u3002<br \/>\n\u865a\u62df\u73af\u5883\u7684\u540d\u5b57\u53ef\u4ee5\u8bbe\u4e3adjango\uff0c\u4f46\u662f\u9700\u8981\u4f7f\u7528\u4e00\u4e2a\u5bb9\u6613\u7406\u89e3\u7684\u540d\u5b57\u3002<br \/>\n\u4f7f\u7528\u6e90\u4ee3\u7801\u4e2d\u7684django\/bin\/activate\u6765\u542f\u52a8\u865a\u62df\u73af\u5883\u3002<\/p>\n<pre class=\"post-pre\"><code>$ virtualenv django\r\n$ source django\/bin\/activate\r\n<\/code><\/pre>\n<p>\u4e00\u65e6\u6210\u529f\u8fdb\u5165\u865a\u62df\u73af\u5883\uff08django\uff09\u540e\uff0c\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\u4f1a\u663e\u793a\u5728\u6700\u524d\u9762\uff0c\u5c31\u50cf\u4f7f\u7528Django\u7684manage.py\u7b49\u65f6\uff0c\u5fc5\u987b\u8fdb\u5165\u865a\u62df\u73af\u5883\u624d\u80fd\u4f7f\u7528\uff0c\u6240\u4ee5\u8bf7\u6ce8\u610f\u3002<\/p>\n<h2>\u4eceGithub\u4e0a\u514b\u9686\u751f\u6210\u7684\u4ee3\u7801\u3002<\/h2>\n<p>\u6211\u8981\u4eceGitHub\u4e0a\u514b\u9686\u3002<\/p>\n<div>\u7531\u4e8e2021\u5e748\u6708\u5de6\u53f3\uff0c\u7531\u4e8ehttps\u7684\u5b89\u5168\u95ee\u9898\u514b\u9686\u53d8\u5f97\u9ebb\u70e6\uff0c\u6240\u4ee5\u6211\u4eec\u6dfb\u52a0\u4e86\u901a\u8fc7ssh\u514b\u9686\u7684\u65b9\u6cd5\u3002<\/div>\n<p>\u8bf7\u53c2\u8003\u4ee5\u4e0b\u6587\u7ae0\u8fdb\u884c\u514b\u9686\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>\u6211\u51b3\u5b9a\u5c06Django\u9879\u76ee\u514b\u9686\u5230home\u76ee\u5f55\u4e0b\u3002<\/p>\n<pre class=\"post-pre\"><code>$ cd\r\n$ git clone git@github.com:\u30e6\u30fc\u30b6\u30fc\u540d\/\u30ea\u30dd\u30b8\u30c8\u30ea\u540d.git\r\n<\/code><\/pre>\n<p>\u7136\u540e\uff0c\u6211\u4eec\u5c06\u4f7f\u7528\u5728\u672c\u5730\u4e0a\u7f16\u5199\u7684requirements.txt\u6587\u4ef6\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002<\/p>\n<pre class=\"post-pre\"><code>$ ls\r\ndjango  django-aws\r\n$ cd django-aws\r\n$ pip install -r requirements.txt\r\n<\/code><\/pre>\n<h2>\u521b\u5efa.env\u6587\u4ef6<\/h2>\n<p>\u7531\u4e8e\u5728gitignore\u4e2d\u6392\u9664\u4e86\uff0c\u672c\u5730\u6ca1\u6709.env\u6587\u4ef6\u3002<br \/>\n\u5982\u679c\u4e0d\u521b\u5efa\uff0c\u65e0\u6cd5\u8bfb\u53d6Django\u4f7f\u7528\u7684\u5bc6\u94a5\u7b49\uff0c\u4f1a\u51fa\u73b0\u9519\u8bef\uff0c\u6240\u4ee5\u9700\u8981\u521b\u5efa\u3002<\/p>\n<p>\u8bf7\u5728manage.py\u7684\u540c\u4e00\u76ee\u5f55\u5c42\u7ea7\u4e0b\u521b\u5efa\u4e0e\u672c\u5730\u76f8\u540c\u7684\u6587\u4ef6\u3002<\/p>\n<pre class=\"post-pre\"><code>$ vim .env\r\n<\/code><\/pre>\n<p>\u8bf7\u5c06\u4ee5\u4e0b\u4e24\u4e2a\u4f4d\u4e8e\u672c\u5730\u7684.env\u6587\u4ef6\u4e2d\u7684\u5185\u5bb9\u7c98\u8d34\uff0c\u5e76\u5728\u4e0b\u65b9\u6dfb\u52a0\u6570\u636e\u5e93\u8fde\u63a5\u8bbe\u7f6e\u3002<\/p>\n<p>\u4f7f\u7528\u4ee5\u4e0b\u89c4\u5219\uff1apostgres:\/\/USER:PASSWORD@HOST:PORT\/NAME\uff0c\u5373\u53ef\u8fde\u63a5\u3002<\/p>\n<pre class=\"post-pre\"><code>SECRET_KEY=1234567890sdogdmsmoa@:dmmgsv94kmvaso(9l\r\nDEBUG=False\r\nDATABASE_URL=postgres:\/\/django:\u3053\u3053\u306b\u3055\u3063\u304d\u8a2d\u5b9a\u3057\u305fDB\u306e\u30d1\u30b9\u30ef\u30fc\u30c9@localhost:\/djangodb\r\nALLOWED_HOSTS=13.111.111.111\r\n<\/code><\/pre>\n<p>\u203b \u4e00\u822c\u800c\u8a00\uff0c\u4f7f\u7528vim\u8fdb\u884c\u7f16\u8f91\u65f6\uff0c\u6309\u4e0bi\u952e\u3002\u4fdd\u5b58\u65b9\u5f0f\u662f\u6309\u4e0besc\u952e\uff0c\u7136\u540e\u8f93\u5165\u5192\u53f7\uff0c\u518d\u8f93\u5165wq\u3002<br \/>\n\u8bf7\u5728AWS EC2\u7684\u63a7\u5236\u53f0\u4e2d\u8f93\u5165ALLOWED_HOSTS\u5b57\u6bb5\uff0c\u5176\u4e2d\u5305\u542b\u516c\u6709IPv4\u5730\u5740\u3002<\/p>\n<p>\u8bf7\u6ce8\u610f\uff1a\u5982\u679c\u60a8\u6ca1\u6709\u8bbe\u7f6e\u6b64\u4e3b\u673a\u7684IP\u548cAWS\u7684\u5f39\u6027IP\u5730\u5740\uff0c\u5728\u6bcf\u6b21\u505c\u6b62\u5b9e\u4f8b\u540e\uff0c\u5b83\u4eec\u90fd\u4f1a\u53d1\u751f\u53d8\u5316\u3002\u6240\u4ee5\uff0c\u5982\u679c\u60a8\u5728\u8bbe\u7f6e\u4e4b\u524d\u505c\u6b62\u4e86\u5b9e\u4f8b\uff0c\u5c31\u9700\u8981\u5728\u8fd9\u91cc\u91cd\u65b0\u8bbe\u7f6e\u3002<\/p>\n<p>\u5982\u679c\u8bbe\u7f6e\u4e86\u5f39\u6027IP\u5730\u5740\uff0c\u5219\u4e0d\u9700\u8981\u91cd\u65b0\u8bbe\u7f6e\uff0c\u4f46\u5982\u679c\u5173\u8054\u7684\u5b9e\u4f8b\u5904\u4e8e\u505c\u6b62\u72b6\u6001\uff0c\u53ef\u80fd\u6bcf\u6708\u4f1a\u4ea7\u751f\u6570\u767e\u65e5\u5143\u7684\u8d39\u7528\uff01\u5982\u679c\u4e0d\u518d\u4f7f\u7528\u5b9e\u4f8b\uff0c\u5219\u6700\u597d\u91ca\u653e\u5f39\u6027IP\u3002<\/p>\n<h2>\u7f16\u8f91settings.py<\/h2>\n<p>\u7531\u4e8e\u6211\u6dfb\u52a0\u4e86\u914d\u7f6e\u6587\u4ef6.env\u7684\u5185\u5bb9\uff0c\u6240\u4ee5\u53ef\u4ee5\u8bfb\u53d6\u5b83\u3002<\/p>\n<pre class=\"post-pre\"><code>$ cd testapp\r\n$ vim settings.py\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code><span class=\"n\">ALLOWED_HOSTS<\/span> <span class=\"o\">=<\/span> <span class=\"n\">env<\/span><span class=\"p\">.<\/span><span class=\"nf\">list<\/span><span class=\"p\">(<\/span><span class=\"sh\">'<\/span><span class=\"s\">ALLOWED_HOSTS<\/span><span class=\"sh\">'<\/span><span class=\"p\">)<\/span>\r\n<\/code><\/pre>\n<h2>\u6267\u884c\u8fc1\u79fb<\/h2>\n<p>\u79fb\u52a8\u5230 manage.py \u6240\u5728\u7684\u76ee\u5f55\uff0c\u5e76\u6267\u884c migrate \u64cd\u4f5c\u3002<\/p>\n<pre class=\"post-pre\"><code>$ python3 manage.py migrate\r\n<\/code><\/pre>\n<p>\u5982\u679c\u8fc1\u79fb\u6210\u529f\uff0c\u5c31\u53ef\u4ee5\u4e86\uff01<\/p>\n<h1>9. \u6211\u4eec\u53ef\u4ee5\u5728\u5f00\u53d1\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u786e\u8ba4\u3002<\/h1>\n<p>\u5982\u679c\u4e0d\u4f7f\u7528Nginx gunicorn\uff0c\u672c\u7ae0\u5c31\u7ed3\u675f\u4e86\u3002<br \/>\n\u8fd4\u56deEC2\u754c\u9762\uff0c\u7f16\u8f91\u201c\u5165\u7ad9\u89c4\u5219\u201d<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/164-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-25 20.00.13.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/165-0.png\" alt=\"_2021-01-26_16.40.55.png\" \/><\/div>\n<p>\u53ea\u8981\u542f\u52a8\u6211\u901a\u5e38\u5728\u672c\u5730\u4f7f\u7528\u7684\u670d\u52a1\u5668\uff0c\u57fa\u672c\u4e0a\u90e8\u7f72\u5c31\u53ef\u4ee5\u7b97\u662f\u5b8c\u6210\u4e86\uff01<\/p>\n<p>\u5f53\u8fd0\u884c\u670d\u52a1\u5668\u65f6\uff0c\u6211\u51b3\u5b9a\u57288000\u7aef\u53e3\u4e0a\u542f\u52a8\uff0c\u56e0\u6b64\u5141\u8bb8\u4e868000\u7aef\u53e3\u3002<\/p>\n<h2>\u7531\u4e8e\u4e00\u5fdc\u5df2\u7ecf\u5b8c\u6210\u4e86\uff0c\u6240\u4ee5\u8bf7\u786e\u8ba4\u4e00\u4e0b\u3002<\/h2>\n<p>\u5728manage.py\u6240\u5728\u7684\u76ee\u5f55\u4e2d\uff0c\u4ee5\u672c\u5730\u670d\u52a1\u5668\u7684\u65b9\u5f0f\u542f\u52a8\u670d\u52a1\u5668\u3002<br \/>\nIP\u5730\u5740\u5168\u90e8\u5141\u8bb8\uff0c\u4f46\u7aef\u53e3\u53f7\u4e3a8000\u3002<br \/>\n\uff08\u6b63\u5982\u5148\u524d\u5728\u5165\u7ad9\u89c4\u5219\u4e2d\u6307\u5b9a\u76848000\u53f7\u7aef\u53e3\uff09<\/p>\n<pre class=\"post-pre\"><code>$ python3 manage.py runserver 0.0.0.0:8000\r\n<\/code><\/pre>\n<p>\u590d\u5236\u516c\u5171IPv4\u5730\u5740\u548c\u7aef\u53e3\u5230\u6d4f\u89c8\u5668\u3002<\/p>\n<blockquote><p>54.250.111.11:8000\uff1a\u4e94\u56db\u70b9\u4e8c\u4e94\u96f6\u70b9\u4e00\u4e00\u4e00\u70b9\u4e00\u4e00\uff0c\u516b\u5343<\/p><\/blockquote>\n<p>\u4ee5\u7c7b\u4f3c\u7684\u65b9\u5f0f\u8fdb\u884c\u8bbf\u95ee\u3002<\/p>\n<h2>\u6211\u6210\u529f\u4e86\u3002\u6682\u65f6\u53ef\u4ee5\u3002<\/h2>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/175-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-26 16.47.10.png\" \/><\/div>\n<p>\u6211\u5df2\u7ecf\u6210\u529f\u90e8\u7f72\u4e86\u4e00\u4e2a\u53ea\u80fd\u663e\u793a\u6587\u672c\u7684\u5e94\u7528\u3002\u5982\u679c\u53ea\u662f\u5236\u4f5c\u4e00\u4e2a\u539f\u578b\u53ef\u80fd\u8fd8\u53ef\u4ee5\uff0c\u4f46\u5982\u679c\u662f\u666e\u901a\u7684Django\u914d\u7f6e\uff0c\u6211\u4eec\u4f1a\u4f7f\u7528gunicorn\u548cnginx\uff0c\u6240\u4ee5\u8ba9\u6211\u4eec\u5c06\u5176\u914d\u7f6e\u597d\u3002<\/p>\n<h1>10. gunicorn\u7684\u914d\u7f6e<\/h1>\n<p>\u4e00\u65e6\u79bb\u5f00\u865a\u62df\u73af\u5883\uff0c\u6211\u4eec\u5f00\u59cb\u8fdb\u884c\u5de5\u4f5c\u3002<\/p>\n<pre class=\"post-pre\"><code>$ deactivate\r\n<\/code><\/pre>\n<p>\u6211\u5c06\u7f16\u5199gunicorn\u7684\u914d\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sudo vim \/etc\/systemd\/system\/gunicorn.service\r\n<\/code><\/pre>\n<p>\u5728\u6211\u8fd9\u91cc\u7684\u60c5\u51b5\u662f\u8fd9\u6837\u7684\u3002<\/p>\n<pre class=\"post-pre\"><code>[Unit]\r\nDescription=gunicorn daemon\r\nAfter=network.target\r\n\r\n[Service]\r\nUser=ubuntu\r\nGroup=www-data\r\nWorkingDirectory=\/home\/ubuntu\/django-aws\r\nExecStart=\/home\/ubuntu\/django\/bin\/gunicorn --access-logfile - --workers 3 --bind unix:\/home\/ubuntu\/django-aws\/testapp.sock testapp.wsgi:application\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/code><\/pre>\n<p>\u5de5\u4f5c\u76ee\u5f55=\/home\/ubuntu\/\u4e0e\u5b58\u50a8\u5e93\u540c\u540d\u7684<\/p>\n<p>ExecStart=\/home\/ubuntu\/\u4eee\u60f3\u74b0\u5883\u7684\u540d\u5b57\/bin\/gunicorn &#8211;access-logfile &#8211; &#8211;workers 3 &#8211;bind unix:\/home\/ubuntu\/\u548c\u4ed3\u5e93\u540d\u5b57\u76f8\u540c\u7684\/Django\u9879\u76ee\u540d\u5b57.sock Django\u9879\u76ee\u540d\u5b57.wsgi:application<\/p>\n<p>\u8bf7\u53ea\u8fdb\u884c\u8c03\u6574\u3002<\/p>\n<h2>Gunicorn\u670d\u52a1\u7684\u81ea\u52a8\u542f\u52a8\u548c\u542f\u7528<\/h2>\n<pre class=\"post-pre\"><code>$ sudo systemctl start gunicorn.service\r\n$ sudo systemctl enable gunicorn\r\n<\/code><\/pre>\n<h1>11. Nginx\u7684\u914d\u7f6e\u3002<\/h1>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u8981\u521b\u5efanginx\u7684\u914d\u7f6e\u6587\u4ef6\u3002<br \/>\nsudo vim \/etc\/nginx\/sites-available\/\u4e0e\u4ed3\u5e93\u540d\u79f0\u76f8\u540c<\/p>\n<pre class=\"post-pre\"><code>$ sudo vim \/etc\/nginx\/sites-available\/django-aws\r\n<\/code><\/pre>\n<p>\u8bf7\u4fee\u6539\u4ee5\u4e0b\u5185\u5bb9\u3002<\/p>\n<pre class=\"post-pre\"><code>server {\r\n        listen 80;\r\n        server_name \u3053\u3053\u306b\u30d1\u30d6\u30ea\u30c3\u30afIP;\r\n\r\n        location = \/favicon.ico {access_log off; log_not_found off;}\r\n        location \/static\/ {\r\n                root \/home\/ubuntu\/\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u540d\u524d\u3068\u540c\u3058;\r\n        }\r\n\r\n        location \/ {\r\n                include proxy_params;\r\n                proxy_pass http:\/\/unix:\/home\/ubuntu\/\u30ea\u30dd\u30b8\u30c8\u30ea\u306e\u540d\u524d\u3068\u540c\u3058\/\u30d7\u30ed\u30b8\u30a7\u30af\u30c8\u540d.sock;\r\n        }\r\n}\r\n<\/code><\/pre>\n<p>\u521b\u5efa\u7b26\u53f7\u94fe\u63a5<\/p>\n<pre class=\"post-pre\"><code>$ sudo ln -s \/etc\/nginx\/sites-available\/django-aws \/etc\/nginx\/sites-enabled\/\r\n<\/code><\/pre>\n<p>\u542f\u52a8 Nginx \u5e76\u6253\u5f00 80 \u7aef\u53e3\u3002<br \/>\n\u521a\u624d\u6267\u884c\u4e86 python manage.py runserver \u7684\u4eba\uff0c\u6682\u65f6\u79fb\u9664\u4e86 8000 \u7aef\u53e3\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sudo systemctl restart nginx\r\n$ sudo ufw delete allow 8000\r\n$ sudo ufw allow 'Nginx Full'\r\n<\/code><\/pre>\n<h1>12. \u5b89\u5168\u7ec4\u8bbe\u7f6e<\/h1>\n<p>\u521a\u521a\uff0c\u5bf9\u901a\u8fc78000\u7aef\u53e3\u7684\u5185\u5bb9\u8fdb\u884c\u4e86\u66f4\u6539\u3002\u66f4\u6539\u4e3a\u4f7f\u7528HTTP\u3002<br \/>\n\u203b\u56e0\u4e3a\u4e0d\u518d\u4f7f\u75288000\u7aef\u53e3\uff0c\u6700\u597d\u5c06\u5176\u5220\u9664\u3002<\/p>\n<p>\u7531\u4e8e\u672c\u6b21\u60c5\u51b5\u4e0b\u91c7\u7528\u4e86Django\uff0c\u6211\u4f1a\u5bf9\u5b89\u5168\u7ec4\u8fdb\u884c\u7f16\u8f91\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/201-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-25 20.03.07.png\" \/><\/div>\n<p>\u68c0\u67e5HTTP\u548c0.0.0.0\/0\uff0c\u5e76\u4fdd\u5b58\u89c4\u5219\u3002<\/p>\n<p>\u91cd\u65b0\u542f\u52a8gunicorn\u3002<\/p>\n<pre class=\"post-pre\"><code>$ sudo systemctl restart gunicorn\r\n<\/code><\/pre>\n<p>\u518d\u8f93\u5165\u4e00\u6b21\u516c\u5171IP\u5730\u5740\u5230URL\u4e2d\uff0c<\/p>\n<blockquote><p>http:\/\/13.111.111.11\/ \u53ef\u4ee5\u7528\u4e0b\u5217\u65b9\u5f0f\u8fdb\u884c\u590d\u8ff0\uff1a<\/p>\n<p>\u8fd9\u662f\u4e00\u4e2a\u7f51\u7ad9\u7684\u7f51\u5740\uff1ahttp:\/\/13.111.111.11\/<\/p><\/blockquote>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/207-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-29 22.40.16.png\" \/><\/div>\n<p>\u8868\u793a\u5b8c\u6210\u4e86\uff01\u4f60\u505a\u5f97\u597d\u5417\uff1f<\/p>\n<h1>13. \u7834\u574f\u7684\u65b9\u6cd5<\/h1>\n<p>\u4e00\u822c\u7684\u7684\u505a\u4e86\u8bd5\u9a8c\u6027\u6587\u7ae0\u5c31\u7ed3\u675f\u4e86\u3002\u4f46\u662f\uff0c\u6211\u4eec\u5df2\u7ecf\u53d1\u5e03\u4e86<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">1\u5e74\u306e\u7121\u6599\u671f\u9593\u904e\u304e\u305f\u306e\u3067\u58ca\u3057\u305f\u3044<\/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\">\u5fc5\u8981\u306a\u304f\u306a\u3063\u305f<\/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\">\u4ed6\u306eEC2\u7acb\u3066\u305f\u3044<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u3082\u3046\u4e00\u56de\u7df4\u7fd2\u3057\u305f\u3044<\/ul>\n<p>\u6211\u8ba4\u4e3a\u6709\u7c7b\u4f3c\u7684\u4e1c\u897f\u3002<br \/>\n\u6240\u4ee5\u6211\u51c6\u5907\u8fc5\u901f\u6467\u6bc1\u5b83\u4eec\u3002<\/p>\n<h2>\u7834\u574f\u65b9\u6cd5 sh\u01d0 f\u01ce)<\/h2>\n<p>\u8fd9\u6b21\u9700\u8981\u7684\u662f<\/p>\n<ul class=\"post-ul\">\n<li style=\"list-style-type: none;\">\n<ul class=\"post-ul\">EC2\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u7d42\u4e86\u3055\u305b\u308b<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<ul class=\"post-ul\">\u30bb\u30ad\u30e5\u30ea\u30c6\u30a3\u30b0\u30eb\u30fc\u30d7\u3092\u524a\u9664<\/ul>\n<p>\u5982\u679c\u60a8\u60f3\u8981\u505c\u6b62\u6536\u8d39\uff0c\u53ea\u9700\u7ec8\u6b62\u6700\u5c0f\u9650\u5ea6\u7684EC2\u5373\u53ef\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/217-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-30 17.07.10.png\" \/><\/div>\n<p>\u5e0c\u671b\u522a\u9664\u7684\u662f\u300c\u7d42\u4e86\u300d\u3002\u5e0c\u671b\u4f60\u628a\u300c\u524a\u9664\u300d\u5beb\u4e0a\u53bb\u5566 ?<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/219-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-30 17.09.10.png\" \/><\/div>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/220-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-30 17.10.46.png\" \/><\/div>\n<p>\u8fd9\u5c31\u662f\u7ed3\u675f\u4e86\u3002<\/p>\n<h2>\u4f7f\u7528\u5f39\u6027IP\u7684\u4eba\u8fdb\u884c\u5f00\u653e<\/h2>\n<p>\u53e6\u5916\uff0c\u8fd9\u6b21\u6ca1\u4f7f\u7528\uff0c\u53ef\u4ee5\u7565\u8fc7\uff0c\u4f46\u662f\u7ecf\u5e38\u4f1a\u4f7f\u7528\u5230\u4e00\u4e2a\u670d\u52a1\uff0c\u5373\u4f7f\u7528\u5f39\u6027IP\u6765\u786e\u4fdd\u5373\u4f7f\u505c\u6b62\u6216\u91cd\u65b0\u542f\u52a8EC2\u5b9e\u4f8b\uff0cIP\u5730\u5740\u4e0d\u4f1a\u6539\u53d8\u3002<\/p>\n<p>\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528EC2\uff0c\u8bf7\u5728\u5173\u95ed\u5b83\u540e&#8221;\u91ca\u653e&#8221;\u5b83\u3002\u5982\u679c\u4e0d\u91ca\u653e\uff0c\u6bcf\u4e2a\u6708\u5c06\u6536\u53d6\u6570\u767e\u5143\u8d39\u7528\u3002<\/p>\n<p>\u4ece\u5de6\u8fb9\u7684\u5170\u82b1\u5f00\u59cb<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u5f39\u6027IP<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u89e3\u9664\u4e0eEC2\u7684\u7ed1\u5b9a<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u91ca\u653e\u5f39\u6027IP<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\u7ec8\u6b62EC2<\/ol>\n<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<ol>\u5220\u9664\u5b89\u5168\u7ec4<\/ol>\n<p>\u6211\u8ba4\u4e3a\u4f60\u5e94\u8be5\u8bd5\u8bd5\u505a\u4e00\u4e0b\u3002<\/p>\n<h1>\u5b9e\u73b0\u8865\u5168CSS<\/h1>\n<p>\u4f46\u662f\uff0c\u8868\u8fbe\u7684\u76ee\u7684\u5df2\u7ecf\u8fbe\u5230\u4e86\u3002<\/p>\n<blockquote><p>\u53ea\u9700\u8981\u4e00\u4e2a\u9009\u9879\uff0c\u5c06\u4ee5\u4e0b\u5185\u5bb9\u7528\u4e2d\u6587\u8fdb\u884c\u672c\u5730\u5316\u6539\u5199\uff1a<\/p>\n<p>http:\/\/13.111.111.11\/admin\/<\/p>\n<p>\u5341\u4e09\u70b9\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e2a\u70b9\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\u4e00\/admin\/<\/p><\/blockquote>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/231-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-29 22.43.46.png\" \/><\/div>\n<p>CSS\u6ca1\u6709\u751f\u6548\u3002<br \/>\n\u5728\u90e8\u7f72Django\u65f6\uff0c\u5f53\u4f7f\u7528\u9759\u6001\u6587\u4ef6\uff08\u5982CSS\u3001\u56fe\u7247\u3001JS\uff09\u65f6\uff0c\u9700\u8981\u4f7f\u7528\u547d\u4ee4\u3002<br \/>\n\u5728manage.py\u76f8\u540c\u7684\u4f4d\u7f6e\u521b\u5efastatic\u6587\u4ef6\u5939\uff0c\u5e76\u5728settings.py\u7684\u5e95\u90e8\u6dfb\u52a0\u4ee5\u4e0a\u7684\u63cf\u8ff0\u3002<\/p>\n<pre class=\"post-pre\"><code>$ mkdir static\r\n$ cd testapp\r\n$ vim settings.py\r\n<\/code><\/pre>\n<p>\u5728\u4ee3\u7801\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u7528\u4e8e\u8bbe\u7f6e\u4fdd\u5b58CSS\u6587\u4ef6\u7684\u76ee\u5f55\u7684\u914d\u7f6e\u3002<\/p>\n<pre class=\"post-pre\"><code><span class=\"n\">STATIC_URL<\/span> <span class=\"o\">=<\/span> <span class=\"sh\">'<\/span><span class=\"s\">\/static\/<\/span><span class=\"sh\">'<\/span>\r\n<span class=\"n\">STATIC_ROOT<\/span> <span class=\"o\">=<\/span> <span class=\"n\">os<\/span><span class=\"p\">.<\/span><span class=\"n\">path<\/span><span class=\"p\">.<\/span><span class=\"nf\">join<\/span><span class=\"p\">(<\/span><span class=\"n\">BASE_DIR<\/span><span class=\"p\">,<\/span> <span class=\"sh\">'<\/span><span class=\"s\">static<\/span><span class=\"sh\">'<\/span><span class=\"p\">)<\/span>\r\n<\/code><\/pre>\n<pre class=\"post-pre\"><code>$ source ~\/django\/bin\/activate\r\n$ python3 manage.py collectstatic\r\n\r\n132 static files copied to '\/home\/ubuntu\/django-aws\/static'.\r\n<\/code><\/pre>\n<p>\u6211\u8bf4\u4e86\u4e00\u4e0b\uff0c\u5c06\u9759\u6001\u6587\u4ef6\u653e\u5728\/home\/ubuntu\/django-aws\/static\u6587\u4ef6\u5939\u4e2d\u3002<br \/>\n\u8fd9\u4e2a\u6587\u4ef6\u5939\u662f\u521a\u521a\u5728settings.py\u4e2d\u6307\u5b9a\u7684\u76ee\u5f55\u3002<br \/>\n\u73b0\u5728\u5df2\u7ecf\u5b8c\u6210\u4e86\uff0c\u8bd5\u7740\u8bbf\u95ee\u4e00\u4e0b\u3002<\/p>\n<blockquote><p>http:\/\/13.111.111.11\/\u7ba1\u7406\u5458\/ (Mandarin Chinese)<\/p><\/blockquote>\n<p>\u5b8c\u6210\u4e86\u3002<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/240-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-30 2.01.22.png\" \/><\/div>\n<h2>\u6211\u521b\u5efa\u4e86\u4e00\u4e2a\u8d85\u7ea7\u7ba1\u7406\u5458\u5e76\u5c1d\u8bd5\u4f7f\u7528\u7ba1\u7406\u754c\u9762\u3002<\/h2>\n<p>\u56e0\u4e3aDjango\u5728\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u5177\u6709\u521b\u5efa\u7ba1\u7406\u754c\u9762\u7684\u529f\u80fd\uff0c\u6240\u4ee5\u8ba9\u6211\u4eec\u5c1d\u8bd5\u4f7f\u7528\u5b83\u3002\uff08\u975e\u5e38\u65b9\u4fbf\uff01\uff09<br \/>\n\u521b\u5efa\u8d85\u7ea7\u7528\u6237\u5e76\u767b\u5f55\u3002<\/p>\n<pre class=\"post-pre\"><code>$ python3 manage.py createsuperuser\r\nUsername (leave blank to use 'ubuntu'): djangosuper\r\nEmail address:\r\nPassword:\r\nPassword (again):\r\nSuperuser created successfully.\r\n<\/code><\/pre>\n<p>\u8bf7\u63d0\u4f9b\u4e00\u4e2a\u540d\u79f0\u548c\u5bc6\u7801\u6765\u521b\u5efa\u8d26\u6237\u3002\uff08\u8f93\u5165\u5bc6\u7801\u65f6\u4e0d\u4f1a\u663e\u793a\uff09\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u65e0\u9700\u586b\u5199\u7535\u5b50\u90ae\u7bb1\uff0c\u56e0\u6b64\u53ef\u968f\u610f\u586b\u5199\u6216\u4e0d\u586b\u5199\u3002\u8bf7\u8bb0\u4f4f\uff0c\u8fd9\u4e2a\u8d26\u6237\u53ef\u4ee5\u4ece\u5168\u7403\u8bbf\u95ee\uff0c\u6240\u4ee5\u5bc6\u7801\u8981\u8bbe\u7f6e\u590d\u6742\u4e00\u4e9b\u3002<\/p>\n<p>\u6211\u4eec\u5b8c\u6210\u4e86\uff01<\/p>\n<div><img decoding=\"async\" class=\"post-images\" title=\"\" src=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/246-0.png\" alt=\"\u30b9\u30af\u30ea\u30fc\u30f3\u30b7\u30e7\u30c3\u30c8 2021-01-30 2.09.33.png\" \/><\/div>\n<p>\u60a8\u53ef\u4ee5\u901a\u8fc7\u6b64\u754c\u9762\u5411\u6570\u636e\u5e93\u6dfb\u52a0\u6570\u636e\u6216\u8bbe\u7f6e\u8bbf\u95ee\u9650\u5236\u3002<br \/>\n\u8bf7\u53c2\u8003\u6211\u4ee5\u524d\u7f16\u5199\u7684\u6709\u5173\u5904\u7406\u6b64\u7c7b\u4e8b\u9879\u7684Django\u5e94\u7528\u7a0b\u5e8f\u7684\u6587\u7ae0\u3002<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528AWS EC2\u4e91\u670d\u52a1\u5668\uff0c\u4ee5\u6700\u7b80\u5355\u7684\u914d\u7f6e\u5c06Nginx\u3001gunicorn\u548cpostgresql\u90e8\u7f72\u3002 \u5982\u679c\u8981\u7528 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-49345","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>\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011 - 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\/\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528aws-ec2\u79d2\u901f\u90e8\u7f72django-3\u5e94\u7528\u7a0b\u5e8f\u3010nginx\u3001\/\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011\" \/>\n<meta property=\"og:description\" content=\"\u4f7f\u7528AWS EC2\u4e91\u670d\u52a1\u5668\uff0c\u4ee5\u6700\u7b80\u5355\u7684\u914d\u7f6e\u5c06Nginx\u3001gunicorn\u548cpostgresql\u90e8\u7f72\u3002 \u5982\u679c\u8981\u7528 [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/zh\/blog\/\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528aws-ec2\u79d2\u901f\u90e8\u7f72django-3\u5e94\u7528\u7a0b\u5e8f\u3010nginx\u3001\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:published_time\" content=\"2023-08-16T00:11:16+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-30T09:08:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/2-0.png\" \/>\n<meta name=\"author\" content=\"\u6e05, \u5b87\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"\u6e05, \u5b87\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \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\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/\",\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/\",\"name\":\"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011 - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#website\"},\"datePublished\":\"2023-08-16T00:11:16+00:00\",\"dateModified\":\"2024-04-30T09:08:50+00:00\",\"author\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.silicloud.com\/zh\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011\"}]},{\"@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\/1a6ecd3d914d22a5ac32791ffc1fbd8e\",\"name\":\"\u6e05, \u5b87\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g\",\"caption\":\"\u6e05, \u5b87\"},\"url\":\"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/\"},{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/#local-main-organization-logo\",\"url\":\"\",\"contentUrl\":\"\",\"caption\":\"Blog - Silicon Cloud\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011 - 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\/\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528aws-ec2\u79d2\u901f\u90e8\u7f72django-3\u5e94\u7528\u7a0b\u5e8f\u3010nginx\u3001\/","og_locale":"zh_CN","og_type":"article","og_title":"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011","og_description":"\u4f7f\u7528AWS EC2\u4e91\u670d\u52a1\u5668\uff0c\u4ee5\u6700\u7b80\u5355\u7684\u914d\u7f6e\u5c06Nginx\u3001gunicorn\u548cpostgresql\u90e8\u7f72\u3002 \u5982\u679c\u8981\u7528 [&hellip;]","og_url":"https:\/\/www.silicloud.com\/zh\/blog\/\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528aws-ec2\u79d2\u901f\u90e8\u7f72django-3\u5e94\u7528\u7a0b\u5e8f\u3010nginx\u3001\/","og_site_name":"Blog - Silicon Cloud","article_published_time":"2023-08-16T00:11:16+00:00","article_modified_time":"2024-04-30T09:08:50+00:00","og_image":[{"url":"https:\/\/cdn.silicloud.com\/blog-img\/blog\/img\/657d8aa5913a08637a6cabf0\/2-0.png"}],"author":"\u6e05, \u5b87","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"\u6e05, \u5b87","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/","url":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/","name":"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011 - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#website"},"datePublished":"2023-08-16T00:11:16+00:00","dateModified":"2024-04-30T09:08:50+00:00","author":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/1a6ecd3d914d22a5ac32791ffc1fbd8e"},"breadcrumb":{"@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.silicloud.com\/zh\/blog\/"},{"@type":"ListItem","position":2,"name":"\u3010\u8be6\u7ec6\u89e3\u91ca\u3011\u5982\u4f55\u4f7f\u7528AWS EC2\u79d2\u901f\u90e8\u7f72Django 3\u5e94\u7528\u7a0b\u5e8f\u3010Nginx\u3001gunicorn\u3001PostgreSQL\u3011"}]},{"@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\/1a6ecd3d914d22a5ac32791ffc1fbd8e","name":"\u6e05, \u5b87","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b2016c18459a605fc469c7566608f5686491baa112d0871ee613f61b7210565?s=96&d=mm&r=g","caption":"\u6e05, \u5b87"},"url":"https:\/\/www.silicloud.com\/zh\/blog\/author\/qingyu\/"},{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.silicloud.com\/zh\/blog\/%e3%80%90%e8%af%a6%e7%bb%86%e8%a7%a3%e9%87%8a%e3%80%91%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8aws-ec2%e7%a7%92%e9%80%9f%e9%83%a8%e7%bd%b2django-3%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f%e3%80%90nginx%e3%80%81\/#local-main-organization-logo","url":"","contentUrl":"","caption":"Blog - Silicon Cloud"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/49345","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\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/comments?post=49345"}],"version-history":[{"count":2,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/49345\/revisions"}],"predecessor-version":[{"id":93188,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/posts\/49345\/revisions\/93188"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/media?parent=49345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/categories?post=49345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/zh\/blog\/wp-json\/wp\/v2\/tags?post=49345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}