我正在运行Ubuntu 14.04上的apache2 Web服务器。
默认情况下,当我在
我在/home/ubuntu/myprojects/位置有一个Flask应用程序。该Flask应用程序在virtualenv上运行,并具有呈现HTML文件的正确文件夹结构。 以下是文件夹结构: /home/ubuntu/myprojects/hello/hello.py(呈现HTML的Flask应用程序) /home/ubuntu/myprojects/hello/templates/hello.html
Flask应用程序代码如下:
在
http://localhost
上启动apache Web服务器时,会看到从/var/www/html/index.html文件启动的“Apache2 Ubuntu默认页面”。我在/home/ubuntu/myprojects/位置有一个Flask应用程序。该Flask应用程序在virtualenv上运行,并具有呈现HTML文件的正确文件夹结构。 以下是文件夹结构: /home/ubuntu/myprojects/hello/hello.py(呈现HTML的Flask应用程序) /home/ubuntu/myprojects/hello/templates/hello.html
Flask应用程序代码如下:
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("hello.html")
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')
当我运行http://localhost:5000
时,将呈现hello.html。
当调用http://localhost
时,我想要从hello.py flask应用程序呈现hello.html,而不需要指定任何端口号。
为了实现这一点,我添加了以下代码:
app.run(host='0.0.0.0', port=80)
但是,当我运行 Flask 应用时,它会出现错误并退出:
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
Traceback (most recent call last):
File "hello.py", line 21, in <module>
app.run(host='0.0.0.0', port=80)
File "/home/ubuntu/myproject/venv/local/lib/python2.7/site-packages/flask/app.py", line 772, in run
run_simple(host, port, self, **options)
File "/home/ubuntu/myproject/venv/local/lib/python2.7/site-packages/werkzeug/serving.py", line 618, in run_simple
test_socket.bind((hostname, port))
File "/usr/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied
我不知道我做错了什么。在http://localhost
上,来自/var/www/html/的index.html正在呈现。
除此之外,当我使用mod_wsgi时,我添加了下面的代码 添加application.wsgi
import os, sys, logging
logging.basicConfig(stream=sys.stderr)
PROJECT_DIR = '/home/ubuntu/myproject/hello'
activate_this = os.path.join(PROJECT_DIR, 'bin', 'activate_this.py')
execfile(activate_this, dict(__file__=activate_this))
sys.path.append(PROJECT_DIR)
from hello import app as application
在
/etc/apache2/sites-available/000-default.conf
文件中,我添加了如下内容:<VirtualHost *:80>
WSGIDaemonProcess FunRoute user=ubuntu group=root threads=5
WSGIScriptAlias / /home/ubuntu/myproject/FunRoute/application.wsgi
<Directory /home/ubuntu/myproject/FunRoute/>
WSGIProcessGroup FunRoute
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
我将hello.py文件改回了原始状态:
app.run(host='0.0.0.0')
但是当我尝试启动http://localhost时,却收到了403 Forbidden
错误。
Forbidden
You don't have permission to access / on this server.
Apache/2.4.7 (Ubuntu) Server at 52.8.217.39 Port 80
/var/log/apache2/error.log
,看看是什么导致了这个403错误。 - metatoasterAH01630: client denied by server configuration: /home/ubuntu/myproject/hello/application.wsgi
。 - Rookie