EC2上部署Django个人网站并连上Godaddy域名

BabbleDay posted @ 2015年6月28日 21:56 in Web Development with tags django EC2 Godaddy Elastic IP Domain Name , 2737 阅读

项目命名为PersonalWebsite,后面各处取名时会用到。此项目数据库用的是Django自带的sqlite。

第一步:在AWS上创建新的EC2,选择Ubuntu Free Tier

这就是网站服务器了,可以通过ssh连接之。为了方便,写一个命令:$ ssh PersonalWebsite

# edit ~/.ssh/config

Host PersonalWebsite
HostName <ec2_hostname>
User ubuntu
IdentityFile "~/.ssh/<your_key_pair>.pem"

安装必要程序。可以通过执行写好的脚本文件

 

# filename: install.sh

sudo apt-get update && upgrade;
sudo apt-get install apache2 libapache2-mod-wsgi;
sudo apt-get install python-pip;
sudo pip install django;
sudo apt-get install mysql-server python-mysqldb;
sudo apt-get install git;

 

第二步 植入网站

先从github上拉下来: $ git clone <url>

我的Django网站文件结构如下

 

~/
    PersonalWebsite/
        App/
            __init__.py
            admin.py
            models.py
            tests.py
            urls.py
            views.py
        PersonalWebsite/
            __init__.py
            settings.py
            urls.py
            views.py
            wsgi.py
        static/
            css/
            images/
        template/
            app/
            other_html.html
        db.sqlite3
        manage.py

配置Apache服务器,在/etc/apache2/sites-enabled/PersonalWebsite.conf里声明wsgi.py和静态文件的路径。

 

WSGIScriptAlias / /home/ubuntu/PersonalWebsite/PersonalWebsite/wsgi.py
WSGIPythonPath /home/ubuntu/PersonalWebsite
<Directory /home/ubuntu/PersonalWebsite/PersonalWebsite>
    <Files wsgi.py>
        Order deny,allow
        Require all granted
    </Files>
</Directory>

Alias /media/ /home/ubuntu/PersonalWebsite/media/ 
Alias /static/ /home/ubuntu/PersonalWebsite/static/

<Directory /home/ubuntu/PersonalWebsite/static>
    Require all granted
</Directory>

<Directory /home/ubuntu/PersonalWebsite/media>
    Require all granted
</Directory> 

 

第三步 绑定域名

  1. 首先,在AWS里将EC2绑定一个Elastic IP(The Elastic IP address assigned to the instance, if applicable. Elastic IP addresses are static IP addresses assigned to your account that you can quickly remap to other instances.
    操作路径:AWS Dashboard => (左侧导航栏)Security & Network下的Elastic IP
     
  2. 在Godday.com购买了example.com域名
    在Domain => Domain Details => DNS ZONE FILE 中修改A(Host)的Record:
    使 @ (即此域名)对应上一步中的Elastic IP

 

小贴士

网站的更新流程可以是:在本地开发 --> 上传至Github --> 登入EC2 --> $ git pull --> 重启Apache

Avatar_small
cleaning services ab 说:
2019年9月19日 03:15

Clean-up service team owners usually are entrepreneurs exactly who work beneath names connected with franchise corporations. They may are dedicated to cleaning households or business oriented buildings. No matter what, they cleaner, pick in place trash, fresh restrooms or maybe bathrooms in addition to shampoo green area rugs.

Avatar_small
maids in dubai 说:
2020年6月30日 21:21

Should you have decided your mind to try maid system, various various important points how about that you need to consider keeping yourself in typically the safer end. Points prefer legal is so important including licensing, tax not to mention insurance and also things prefer sanitation are really important some things to consider before typically the hiring system.

Avatar_small
painters in Dubai 说:
2020年6月30日 21:21

You can't always believe in the ads and recommendations. Since selecting a painter with regard to office is among the most essential investments that you experienced, you won't let anybody paint the actual walls of your property. For this particular reason, you should call on the professional artist for workplace who knows how you can treat your workplace with the required attention.

Avatar_small
rapidity-news 说:
2021年3月22日 05:13

Up to the sunshine shines in the daytime and the particular moon during the night, things take place every next. And each second can be an opportunity regarding news copy writers and reporters. Countless fresh media are composed everyday, yet are they will worth reading-about? Several are, but not these.

Avatar_small
Click Here To Know M 说:
2022年5月27日 22:03

I am very enjoyed for this blog. Its an informative topic. It help me very much to solve some problems. Its opportunity are so fantastic and working style so speedy.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter