質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

CGI

CGI(Common Gateway Interface)とは、Webサーバー上でユーザプログラム動作させる仕組みのこと。また、動かす前提のプログラムをCGIと呼ぶこともあります。HTMLなどの静的な情報に限らず、プログラムの処理結果をベースにした動的情報の提供が可能です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

.htaccess

Apacheウェブサーバーにおいて、ディレクトリ単位で設置及び設定を行う設定ファイルを指します。

Q&A

1回答

3323閲覧

coreserver python 3 django2 500 internal error

komatt

総合スコア12

Django

DjangoはPythonで書かれた、オープンソースウェブアプリケーションのフレームワークです。複雑なデータベースを扱うウェブサイトを開発する際に必要な労力を減らす為にデザインされました。

CGI

CGI(Common Gateway Interface)とは、Webサーバー上でユーザプログラム動作させる仕組みのこと。また、動かす前提のプログラムをCGIと呼ぶこともあります。HTMLなどの静的な情報に限らず、プログラムの処理結果をベースにした動的情報の提供が可能です。

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

.htaccess

Apacheウェブサーバーにおいて、ディレクトリ単位で設置及び設定を行う設定ファイルを指します。

0グッド

0クリップ

投稿2019/06/04 17:20

編集2019/06/04 17:36

coreserver(https://cp.coreserver.jp/)

および

さくらレンタルサーバースタンダートプラン(https://www.sakura.ne.jp)

にて

pyenv [python3.7.3] django2.2

環境で djangoを起動させようと努力したが、500 Internal Server Error
と出てしまい起動できない。

多分 .htaccess と django.cgi の設定が上手く行ってないのだとは思うのだが、あらゆる可能性に挑戦したが一向に解決出来ず。

試したこと

ここのサイトに書かれている通りに全て構築
https://qiita.com/twinoze/items/5bd62a2bc08fee7596f1

次に
https://akasatanahama.com/posts/2/
https://akasatanahama.com/posts/3/
https://akasatanahama.com/posts/16/

の順でサイトを構築したが上手くいかない必ず500 Internal Server Errorが出現する

coreserverにて

~/public_html/ここ

ここ と書かれている部分を
hogehoge.comのrootディレクトリにcoreserverの設定画面で設定.

試しに

~/public_html/index.html

でhello world して
hogehoge.com に飛んだらhello worldしたのでディレクトリ階層はちゃんと設定できていると思われる。

次にローカルにて

django-admin startproject mysite

して

mysite
├── manage.py
└── mysite
,,,,├── init.py
,,,,├── settings.py
,,,,├── urls.py
,,,,└── wsgi.py

を作って [https://qiita.com/twinoze/items/5bd62a2bc08fee7596f1] の通りに hello world 出来るアプリを作り

python manage.py runserver してローカルで
http://127.0.0.1:8000
を立ち上げて hello world 出来ているかを確認。

ちゃんと hello world してました。

ここから FTP接続してサイトに書いてある通りに設定し階層構造をこのように設定し

~/public_html/
,,,, mysite
,,,,,,,, ├── manage.py
,,,,,,,, └── mysite
,,,,,,,, ├── init.py
,,,,,,,, ├── settings.py
,,,,,,,, ├── urls.py
,,,,,,,, └── wsgi.py
,,,, .htaccess
,,,, django.cgi

public-html には mysite .htaccess django.cgi の三つが入っている状態にし

chmod 705 django.cgi

をしてdjango.cgiのパーミッションを変更

.htaccess の内容

ewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ django.cgi/$1 [QSA,L]

django.cgi の内容

#!/virtual/hogehoge/.pyenv/shims/python # encoding: utf-8 """ django-.cgi A simple cgi script which uses the django WSGI to serve requests. Code copy/pasted from PEP-0333 and then tweaked to serve django. http://www.python.org/dev/peps/pep-0333/#the-server-gateway-side This script assumes django is on your sys.path, and that your site code is at /djangoproject/src. Copy this script into your cgi-bin directory (or do whatever you need to to make a cgi script executable on your system), and then update the paths at the bottom of this file to suit your site. This is probably the slowest way to serve django pages, as the python interpreter, the django code-base and your site code has to be loaded every time a request is served. FCGI and mod_python solve this problem, use them if you can. In order to speed things up it may be worth experimenting with running uncompressed zips on the sys.path for django and the site code, as this can be (theorectically) faster. See PEP-0273 (specifically Benchmarks). http://www.python.org/dev/peps/pep-0273/ Make sure all python files are compiled in your code base. See http://docs.python.org/lib/module-compileall.html """ import os, sys # Change this to the directory above your site code. # sys.path.append("/virtual/hogehoge/.pyenv/versions/3.7.3/lib/python3.7/site-packages") # sys.path.append("/virtual/public_html/mysite") def run_with_cgi(application): environ = dict(os.environ.items()) environ['PATH_INFO'] = environ.get('PATH_INFO', "/") environ['wsgi.input'] = sys.stdin.buffer environ['wsgi.errors'] = sys.stderr.buffer environ['wsgi.version'] = (1,0) environ['wsgi.multithread'] = False environ['wsgi.multiprocess'] = True environ['wsgi.run_once'] = True if environ.get('HTTPS','off') in ('on','1'): environ['wsgi.url_scheme'] = 'https' else: environ['wsgi.url_scheme'] = 'http' headers_set = [] headers_sent = [] def write(data): if not headers_set: raise AssertionError("write() before start_response()") elif not headers_sent: # Before the first output, send the stored headers status, response_headers = headers_sent[:] = headers_set sys.stdout.buffer.write(('Status: %s\r\n' % status).encode("ascii")) for header in response_headers: sys.stdout.buffer.write(('%s: %s\r\n' % header).encode("ascii")) sys.stdout.buffer.write(('\r\n').encode("ascii")) sys.stdout.buffer.write(data) sys.stdout.buffer.flush() def start_response(status,response_headers,exc_info=None): if exc_info: try: if headers_sent: # Re-raise original exception if headers sent raise exc_info[0](exc_info[1]).with_traceback(exc_info[2]) finally: exc_info = None # avoid dangling circular ref elif headers_set: raise AssertionError("Headers already set!") headers_set[:] = [status,response_headers] return write result = application(environ, start_response) try: for data in result: if data: # don't send headers until body appears write(data) if not headers_sent: write('') # send headers now if body was empty finally: if hasattr(result,'close'): result.close() # Change to the name of your settings module os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' from django.core.wsgi import get_wsgi_application run_with_cgi(get_wsgi_application()) コード

のように設定

mysite内部の setting.pyの

ALLOWED_HOSTS = [‘hogehoge.com’]

と設定

.bashrc と .bash_profile はともに

/

(root)ディレクトリに置いております。

.bashrc の中身

export PYTHONPATH=/virtual/hogehoge/.pyenv/versions/3.7.3/lib/python3.7/site-packages

.bash_profile の中身

export PYENV_ROOT=$HOME/.pyenv export PATH=$PYENV_ROOT/bin:$PATH eval "$(pyenv init -)"

中身を全部消して、3回程度1から試したのですが、一向に 500 Internal Server Error から抜け出せません。

抜けや書き込み足らずがあると思いますが指摘していただけましたら書き込みます。

何卒何かアドバイスをいただけたら幸いです。よろしくお願いします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

gh640

2019/06/05 05:06

500 Internal Server Error という情報だけをもとにデバッグするのは大変なので、まずは詳細のログを確認されてみてはいかがでしょうか。もしログをご覧になって原因が絞り込めればそれでよいですし、わからなければ質問文に追記されるとよいのかな、と思います。
gh640

2019/06/05 05:12

ちなみに、質問文に記載されている .htaccess の中身にタイポ(貼り付けミス?)があるようです: `ewriteEngine` 。
komatt

2019/06/06 11:59

ご回答ありがとうございます。タイポミス等の修正等、あれからも色々手を尽くしたのですが、一向に問題が解決できないため、諦めました。わざわざご回答ありがとうございました。
guest

回答1

0

私もさくらレンタルサーバースタンダートプランで、Djangoをcgi4で動作させています。

テンプレートは以下を参考にしました。
https://qiita.com/okoppe8/items/4cc0f87ea933749f5a49

cgiの動作は同様に以下を参考にしました。
https://akasatanahama.com/posts/16/

さくらインターネットコントロールパネルの「アクセスログの設定」⇒「エラーログ」に沢山エラーを出力しているので、順につぶしていき、現在は動作しています。
エラーログは確認しましたか?

投稿2019/08/01 00:35

Imasam.00

総合スコア8

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問