gpt4 book ai didi

flask - apache2 没有在本地服务器上显示 flask 应用程序

转载 作者:行者123 更新时间:2023-12-02 15:16:04 24 4
gpt4 key购买 nike

我正在学习本教程: https://pythonprogramming.net/creating-first-flask-web-app/?completed=/flask-web-development-introduction/

在我的本地服务器上(本地网络上的家用计算机)。Flask 本身正常启动

>>> python /var/www/FlaskApp/FlaskApp/__init__.py 
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
127.0.0.1 - - [31/Oct/2016 22:56:29] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [31/Oct/2016 22:56:29] "GET /favicon.ico HTTP/1.1" 404 -

flask starts但无论如何,Apache 都会显示其默认网页。

sudo a2enmod wsgi

Module wsgi already enabled

cat/var/www/FlaskApp/FlaskApp/init.py

from flask import Flask
app = Flask(__name__)
@app.route('/')
def homepage():
return "Hi There, how you're doin?"
if __name__ == "__main__":
app.run()(debug=True)

cat/etc/apache2/sites-available/FlaskApp.conf

<VirtualHost *>
ServerName dagzserv
ServerAdmin my@email.com
WSGIScriptAlias / /var/www/FlaskApp/flaskapp.wsgi
<Directory /var/www/FlaskApp/FlaskApp/>
Require all granted
</Directory>
Alias /static /var/www/FlaskApp/FlaskApp/static
<Directory /var/www/FlaskApp/FlaskApp/static/>
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

sudo a2ensite FlaskApp

Site FlaskApp already enabled

我尝试添加 app.run(host='0.0.0.0', port=5000)我在本地网络 (10.0.1.xxx) 中确实有/etc/hosts dagserv 作为我的 ip还尝试将 ServerName 作为本地主机。

我不明白的一件事是 Apache 究竟是如何找到“FlaskApp.conf”的,但我认为它正在扫描其配置目录(/etc/apache2/sites-available/FlaskApp.conf)

我在/var/logs/apache2 中没有收到任何错误

猫访问.log

10.0.1.14 - - [31/Oct/2016:22:46:52 -0700] "GET / HTTP/1.1" 200 3524 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
10.0.1.14 - - [31/Oct/2016:22:49:14 -0700] "GET / HTTP/1.1" 200 3524 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
10.0.1.14 - - [31/Oct/2016:22:49:15 -0700] "GET / HTTP/1.1" 200 3523 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36"
10.0.1.101 - - [31/Oct/2016:22:56:18 -0700] "GET /favicon.ico HTTP/1.1" 404 499 "-" "Mozilla/5.0 (X11; Ubuntu; Linux armv7l; rv:49.0) Gecko/20100101 Firefox/49.0"

猫错误.log

[Mon Oct 31 22:45:47.288264 2016] [wsgi:warn] [pid 982] mod_wsgi: Compiled for Python/2.7.11.
[Mon Oct 31 22:45:47.288623 2016] [wsgi:warn] [pid 982] mod_wsgi: Runtime using Python/2.7.12.
[Mon Oct 31 22:45:47.314433 2016] [mpm_prefork:notice] [pid 982] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Mon Oct 31 22:45:47.314616 2016] [core:notice] [pid 982] AH00094: Command line: '/usr/sbin/apache2'
[Mon Oct 31 22:48:52.171206 2016] [mpm_prefork:notice] [pid 982] AH00169: caught SIGTERM, shutting down
[Mon Oct 31 22:48:53.766824 2016] [wsgi:warn] [pid 2360] mod_wsgi: Compiled for Python/2.7.11.
[Mon Oct 31 22:48:53.766940 2016] [wsgi:warn] [pid 2360] mod_wsgi: Runtime using Python/2.7.12.
[Mon Oct 31 22:48:53.775947 2016] [mpm_prefork:notice] [pid 2360] AH00163: Apache/2.4.18 (Ubuntu) mod_wsgi/4.3.0 Python/2.7.12 configured -- resuming normal operations
[Mon Oct 31 22:48:53.776083 2016] [core:notice] [pid 2360] AH00094: Command line: '/usr/sbin/apache2'

最佳答案

1。 Apache 如何找到“FlaskApp.conf”

/etc/apache2/apache2.conf 中有一行包含虚拟主机配置:

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

Apache2 服务器将加载 apache2.conf 并且还包括虚拟主机配置。

2。为什么 Apache 无论如何都会显示其默认网页。

如果您通过 IP 地址访问服务器,Apache 将根据其在 /etc/sites-available/000-default.conf 中的默认站点配置返回。所以如果你想通过 IP 地址访问你的 WSGI 服务器,你应该先禁用 Apache 默认站点配置:

sudo a2dissite 000-default.conf
service apache2 restart

关于flask - apache2 没有在本地服务器上显示 flask 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40354966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com