我已经用Apache部署了Flask应用程序。 / var / www / FlaskApp /下的目录结构如下
./FlaskApp/__init__.py
./FlaskApp/oracledb.py
./FlaskApp/templates
./FlaskApp/static
./FlaskApp/static/css
./FlaskApp/static/conf/inv_conf.yml
inv_conf.yml包含数据库连接参数。 oracledb.py包含在 init .py
中导入的DB类。class OracleDB:
def __init__(self):
with open('static/conf/inv_conf.yaml', 'r') as file:
conf = yaml.load(file)
init .py导入
之类的类from oracledb import OracleDB
app = Flask(__name__)
db = OracleDB()
当我访问应用程序时,从apache获取错误信息
[Sat May 25 11:17:53.158072 2019] [:error] [pid 84236] File "/var/www/FlaskApp/FlaskApp/oracledb.py", line 7, in __init__
[Sat May 25 11:17:53.158074 2019] [:error] [pid 84236] with open('static/conf/inv_conf.yaml', 'r') as file:
[Sat May 25 11:17:53.158078 2019] [:error] [pid 84236] IOError: [Errno 2] No such file or directory: 'static/conf/inv_conf.yaml'
但是如果我将inv_conf.yml放在系统根目录'/'下,则可以正常工作。能否请您帮我解决相对路径的问题以及如何解决此问题?
我的httpd.conf就像
<VirtualHost *:80>
ServerName <server name>
WSGIDaemonProcess FlaskApp user=apache group=apache
WSGIScriptAlias /inventory /var/www/FlaskApp/FlaskApp.wsgi
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp>
WSGIProcessGroup FlaskApp
WSGIApplicationGroup %{GLOBAL}
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
wsgi文件是
[root@slc10xxi FlaskApp]# cat FlaskApp.wsgi
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)
sys.path.insert(0, '/var/www/FlaskApp/')
from FlaskApp import app as application