ジャンゴ - CentOSのLinuxは独自のローカルDjangoプロジェクトを展開する学習します

序文

Djangoは他の小さなパートナーがアクセスできるように、Linuxのサーバーにデプロイする方法を独自のローカルのプロジェクトを、書かれましたか?CentOSのシステムのこの部分は、例えば、Linuxサーバへのローカル書かDjangoプロジェクトの展開
環境を準備します:

:環境の準備
1. Linuxのサーバーオペレーティングシステム:CentOSの7.4 64魏
2.python3.6を(すでに良い建て)
3.django-2.1.4を

Djangoの環境準備

すでにpython3.6.8環境をインストールしても、ピップを構成し、直接にインストールジャンゴをインストールPIP、ジャンゴ・ジャンゴ-2.1.4-ビット版をインストール

ジャンゴをインストールするPIP

[root@yoyo ~]# pip -V
pip 18.1 from /usr/local/python3/lib/python3.6/site-packages/pip (python 3.6)
[root@yoyo ~]# pip install django Looking in indexes: http://mirrors.aliyun.com/pypi/simple/ Collecting django Downloading http://mirrors.aliyun.com/pypi/packages/fd/9a/0c028ea0fe4f5803dda1a7afabeed958d0c8b79b0fe762ffbf728db3b90d/Django-2.1.4-py3-none-any.whl (7.3MB) 100% |████████████████████████████████| 7.3MB 4.8MB/s Collecting pytz (from django) Downloading http://mirrors.aliyun.com/pypi/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl (506kB) 100% |████████████████████████████████| 512kB 60.9MB/s Installing collected packages: pytz, django Successfully installed django-2.1.4 pytz-2018.7

Djangoのプロジェクトコード

Linuxサーバ上でDjangoの環境の準備が完了し、次のステップは、プロジェクトコードをDjangoのためにあるサーバー上のディレクトリにコピーし、ローカルコンピュータを介して転送されてきた
xftpツールによって示されるように、すべてのローカルプロジェクトコードは/ optに広めるために/ helloworldディレクトリの下に、ローカルブラウザは何の問題をテストしていないことを条件とします。

スタートジャンゴ

helloworldディレクトリを開き、サービス開始:のpython manage.pyのrunserverを

[root@yoyo ~]# cd /opt/helloworld/
[root@yoyo helloworld]# python manage.py runserver
Performing system checks...

System check identified no issues (0 silenced). You have 18 unapplied migration(s). Your project may not work properly until you apply the migrations for app(s): admin, auth, contenttypes, hello, sessions. Run 'python manage.py migrate' to apply them. January 04, 2019 - 08:31:40 Django version 2.1.4, using settings 'helloworld.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C.

これは、サーバー上で設定されているので、マシンにのみ訪問することができますので、します。http://127.0.0.1:8000 /、次のPythonコードの検証で

[root@yoyo ~]# python
Python 3.6.8 (default, Jan  2 2019, 16:43:17) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> r = requests.get("http://127.0.0.1:8000/") >>> r.status >>> r.status_code 200 >>> 

そして、ECSアリログイン雲の背景 - セキュリティグループ - 設定ルール - オープンポート8000​​、ブラウザにhttpで入力します。//47.104.xx.xx:8000 /発見アクセスできない

エクストラネットアクセスジャンゴ

起動モードは、他の人がこのマシンへのアクセス権を持つことができるように、あなたはパラメータ0.0.0.0を追加する必要があり、アクセスを開くために、唯一のネイティブアクセスのrunserverデフォルトのpython manage.pyの場合:ポート

python manage.pyをするrunserver 0.0.0.0:8000

^C[root@yoyo helloworld]# python manage.py runserver 0.0.0.0:8000
Performing system checks...

System check identified no issues (0 silenced).
January 04, 2019 - 09:57:15 Django version 2.1.4, using settings 'helloworld.settings' Starting development server at http://0.0.0.0:8000/ Quit the server with CONTROL-C. Invalid HTTP_HOST header: '47.104.x.x:8000'. You may need to add '47.104.x.x' to ALLOWED_HOSTS. Bad Request: / [04/Jan/2019 09:57:20] "GET / HTTP/1.1" 400 59588

ブラウザでのサービスを開始した後に入力します。http://47.104.xx:8000 /、文句を言うでしょう 『無効HTTP_HOSTヘッダ:: '47 .104.xx 8000』あなたは'47 .104.xxを追加する必要があります。「ALLOWED_HOSTSに。」

閉じるデバッグ、セットALLOWED_HOSTS

helloworldの/ settings.pyファイルを開き、次の2行のコードを見つけます

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []

デバッグ機能を閉じて、すべてに設定ALLOWED_HOSTS

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = False

ALLOWED_HOSTS = ["*"]

編集後の保存下では、Djangoのサービスを再起動します

python manage.pyをするrunserver 0.0.0.0:8000

そして、地元のブラウザのアクセスに、あなたは、通常のページを開くことができます

ここでは、単純なDjangoのデモプロジェクトが成功のLinuxサーバーにデプロイされていますので、あなたはあなたの小さな友人を伝えることができ、あなたは少しのウェブサイトを見ていますか〜

おすすめ

転載: www.cnblogs.com/mashuqi/p/10975346.html