Heroku部屬

前置作業




# 進入專案資料夾
cd <專案資料夾>

# 於 .\runtime.txt 告知 Python 版本 (可忽略此步驟使用最新版本)
touch runtime.txt
'''
python-3.6.6
'''

# 於 .\requiements.py 補上 packages
'''
dj-database-url
dj-static
gunicorn
'''

# 於 .\DjangoRoot\settings.py 變更動靜文件路徑
'''
STATIC_ROOT = 'zfiles_for_static'
MEDIA_ROOT = 'zfiles_for_media'
'''

# 於 .\DjangoRoot\wsgi.py 替代 Cling
'''
from dj_static import Cling
application = Cling(get_wsgi_application())
'''

# 於 .\Procfile 新增運行程序
touch Procfile
'''
web: python manage.py collectstatic --no-input; gunicorn DjangoRoot.wsgi --log-file - --log-level debug
'''

安全配置



# 關閉除錯
# 限制配置網址
# SECURE_PROXY 配置
vim .\DjangoRoot/settings.py

'''
DEBUG = False
ALLOWED_HOSTS = ['<域名:shiveringbulbul.>']
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
'''

# 更新版本
git commit -am "[heroku]" -m "first push to Heroku"




連線 Heroku



# 登入
heroku login
# 開專案
heroku create

# 新增 git remote
heroku git:remote -a <專案名稱 (Heroku):slimofy>
# 開啟 collectstatic 有可能出現靜態文件錯誤
# heroku config:set DISABLE_COLLECTSTATIC=1
# 更新至 Heroku
git push heroku master
heroku domain:add <域名:shiveringbulbul.tk>
heroku domain:add <域名:www.shiveringbulbul.tk>
# 網站初始化

heroku ps:scale web=1

# 資料庫初始化
heroku run python /manage.py migrate
heroku run python /manage.py createsuperuser

# 開啟網頁
heroku open



常用指令


# 開啟網頁
heroku open
# 查看日誌
heroku logs --tail
# 進入機器
heroku run bash
#clock
heroku clock: python clock.py





$ heroku login
$ git init
$ heroku git:remote -a


部署你的程式到Heroku

$ git add .
$ git commit -am "make it better"
$ git push heroku master



UptimeRobot Heroku 喚醒工具