![](/img/trans.png)
[英]Getting 403 forbidden while running flask app on apache(centos 7)
[英]Running Flask on Apache - CentOS
我設置了一個非常簡單的flask應用程序,以在CentOS 6上的Apache中測試部署,但是出現以下錯誤:
[Sat Apr 26 12:44:20 2014] [error] mod_wsgi (pid=29782): Target WSGI script '/var/www/html/sites/rtdsllc/rtdsllc.wsgi' cannot be loaded as Python module.
[Sat Apr 26 12:44:20 2014] [error] mod_wsgi (pid=29782): Exception occurred processing WSGI script '/var/www/html/sites/rtdsllc/rtdsllc.wsgi'.
[Sat Apr 26 12:44:20 2014] [error] Traceback (most recent call last):
[Sat Apr 26 12:44:20 2014] [error] File "/var/www/html/sites/rtdsllc/rtdsllc.wsgi", line 10, in <module>
[Sat Apr 26 12:44:20 2014] [error] from rtdsllc import app as application
[Sat Apr 26 12:44:20 2014] [error] ImportError: cannot import name app
這是我的wsgi文件:
activate_this = '/var/www/virtualenvs/default/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
path = '/var/www/html/sites/rtdsllc'
import sys
if path not in sys.path:
sys.path.append(path)
from rtdsllc import app as application
這是我的虛擬主機配置:
WSGISocketPrefix run/wsgi
<VirtualHost *:8086>
WSGIDaemonProcess rtdsllc user=apache group=apache threads=5
WSGIScriptAlias /test /var/www/html/sites/rtdsllc/rtdsllc.wsgi
ErrorLog logs/rtdsllc-error_log
CustomLog logs/rtdsllc-access_log common
<Directory /var/www/html/sites/rtdsllc/rtdsllc>
WSGIProcessGroup rtdsllc
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
這是我的燒瓶應用程序:
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=False)
最后是我的文件夾結構:
rtdsllc/
├── rtdsllc
│ ├── __init__.py
│ ├── routes.py
│ ├── static
│ │ ├── css
│ │ ├── img
│ │ └── js
│ └── templates
│ ├── base.html
│ └── index.html
└── rtdsllc.wsgi
是什么賦予了? 我嘗試了各種設置的組合都無濟於事。 在Apache中設置Flask應用的正確方法是什么?
編輯
ls -las rtdsllc/rtdsllc
:
4 drwxr-xr-x. 4 apache apache 4096 Apr 26 13:07 .
4 drwxr-xr-x. 3 apache apache 4096 Apr 25 22:54 ..
0 -rw-r--r--. 1 apache apache 0 Apr 25 20:57 __init__.py
4 -rw-r--r--. 1 apache apache 134 Apr 25 22:55 __init__.pyc
4 -rw-r--r--. 1 apache apache 190 Apr 26 12:48 routes.py
4 -rw-r--r--. 1 apache apache 521 Apr 26 13:07 routes.pyc
4 drwxr-xr-x. 5 apache apache 4096 Apr 25 20:14 static
4 drwxr-xr-x. 2 apache apache 4096 Apr 25 20:19 templates
這樣做:
from rtdsllc import app as application
它將導入:
rtdsllc/rtdsllc/__init__.py
根據您的目錄列表:
0 -rw-r--r--. 1 apache apache 0 Apr 25 20:57 __init__.py
該文件為空,並且其中沒有“ app”對象可通過導入進行拖動。
以下是哪個文件?
app = Flask(__name__)
現在,它不在您嘗試從中導入的位置。
更新1
采用:
from rtdsllc.routes import app as application
如果您的“ app”對象位於“ rtdsllc.routes”中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.