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 から抜け出せません。
抜けや書き込み足らずがあると思いますが指摘していただけましたら書き込みます。
何卒何かアドバイスをいただけたら幸いです。よろしくお願いします。