Ubuntu AWSインスタンスでは、Apacheを設定した後にFlaskサービスを設定しようとしています。os.makedirsはAmazon AWS UbuntuインスタンスでOSErrorにつながる
/var/www/html/myApp/
では、私は他の人の間で、これらのファイルを持っている:ここではmyApp.wsgi
myApp.py
がmyApp.wsgi
の内容は以下のとおりです。ここで
import sys
sys.path.insert(0, '/var/www/html/myApp')
from myApp import app as application
そして/etc/apache2/sites-enabled/000-default.conf
の内容をされています:
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin [email protected]
DocumentRoot /var/www/html
WSGIDaemonProcess charter threads=5
WSGIScriptAlias//var/www/html/myApp/myApp.wsgi
<Directory flaskapp>
WSGIProcessGroup myApp
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
そしてmyApp.py
に、私はディレクトリを作るためにいくつかのコードを持っている:
if not os.path.exists("dir"):
os.makedirs("dir")
をしかし、私はhttp://MY-UBUNTU-EC2-ADDRESS.compute-1.amazonaws.com/myApp/
に私のブラウザをナビゲートするとき、それは500エラーを返します。
私は/var/log/apache2/error.log
でエラーログを確認すると、私はこれらの行を参照してください。私は私のアプリは、ディレクトリまたはファイルを作成する権限を持っていることを確認するために変更する必要がありますどのような
[Mon Aug 14 22:57:06.346698 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] mod_wsgi (pid=6641): Target WSGI script '/var/www/html/myApp/myApp.wsgi' cannot be loaded as Python module.
[Mon Aug 14 22:57:06.346734 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] mod_wsgi (pid=6641): Exception occurred processing WSGI script '/var/www/html/myApp/myApp.wsgi'.
[Mon Aug 14 22:57:06.346750 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] Traceback (most recent call last):
[Mon Aug 14 22:57:06.346768 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] File "/var/www/html/myApp/myApp.wsgi", line 4, in <module>
[Mon Aug 14 22:57:06.346791 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] from myApp import app as application
[Mon Aug 14 22:57:06.346797 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] File "/var/www/html/myApp/myApp.py", line 12, in <module>
[Mon Aug 14 22:57:06.346806 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] os.makedirs(graphicsFiles)
[Mon Aug 14 22:57:06.346811 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] File "/usr/lib/python2.7/os.py", line 157, in makedirs
[Mon Aug 14 22:57:06.346820 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] mkdir(name, mode)
[Mon Aug 14 22:57:06.346837 2017] [:error] [pid 6641:tid 139812646708992] [client IP-ADDRESS-REMOVED:48792] OSError: [Errno 13] Permission denied: 'dir'
を?
ありがとうございました。入力ミスを '/ var/www/html/myApp'に置き換えても同じエラーが出ます。また、 'myapp /'ディレクトリとそのファイルの所有権をユーザ 'www-data'に変更しようとしました。同じエラー。 – Username
'' os.makedirs( "dir") ''を変更しましたか?私が言ったように、そしてドキュメンテーションはあなたに言います、あなたは相対パス名を使うことができません。そのパスは、 ''/dir''に解決される可能性があります。これは書き込みアクセス権がありません。それを計算するか、相対パスではなく完全絶対パスとして設定します。 –