OSError:[Errno 98]地址已在使用,正在Apache2上运行Flask应用程序

2024-10-01 00:26:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我的烧瓶代码在应用程序类型

/some code//


if __name__ == '__main__':
     app.run()

我已经在路径/var/www/AutomateTests中设置了我的wsgi文件

#!/usr/bin/python3.6


import sys
import logging

sys.path.insert(0,"/var/www/AutomateTests/")

from app import app as application
application.root_path = '/var/www/AutomateTests/'

我有/etc/apache2/sites-available/automate_tests.conf

VirtualHost *:80>
                ServerName htstool.arubanetworks.com
                ServerAdmin admin@htstool.arubanetworks.com
                ServerAlias htstool.arubanetworks.com
                ErrorLog /var/log/apache2/hts-error.log
                CustomLog /var/log/apache2/htstool-access.log combined
                WSGIDaemonProcess AutomateTests user=www-data group=www-data threads=5
                WSGIScriptAlias / /var/www/AutomateTests/automate_tests.wsgi
                <Directory /var/www/AutomateTests>
                WSGIProcessGroup AutomateTests
                WSGIApplicationGroup %{GLOBAL}
                Order allow,deny
                        Allow from all
                </Directory>
                LogLevel info
</VirtualHost>

我把一切都安排妥当了,我已经在这个问题上纠缠了好几个星期了。有人能帮我把它放到服务器上吗。有没有一步我错过了。你知道吗

我设置相同的错误,我的端口正在使用,虽然它不是! 看到我的错误了吗

enter image description here

但正如你所看到的,我的端口是空的,没有被使用。我使用命令netstat -ntlp检查

see my ports are listening and not established

有人能帮帮我吗。我被卡住了,在完全检查之前,没有将它标记为已回答。我试过所有的答案,但都不管用!请耐心点,让别人帮我,因为我自己做不到。你知道吗

我的服务器运行正常,我看到了默认的ubuntu页面,这意味着我的apache2服务器运行正常,所以无论是配置还是端口都有问题


Tags: path端口import服务器comlogappwsgi
1条回答
网友
1楼 · 发布于 2024-10-01 00:26:13

当我看到这个的时候,我想到两件事。你知道吗

  1. 服务器上是否安装并运行了Apache?Apache可能正在监听端口80并阻止Python脚本绑定到该端口,但是您运行netcat的方式不会显示这一点。你可以在[服务器ip]:80查这个。

    But as you can see my ports are empty and not being used. I check that using the command netstat -ntlp

注意该命令的第一行输出:(Not all processes could be identified, non-owned process info will not be shown, you would have to be root to see it all.)Apache以提升的权限运行,因此您需要以root身份运行(将sudo附加到命令的开头)以查看其端口绑定。我敢打赌这就是问题所在。修复后,您可能会遇到以下问题:

  1. 你是以root身份运行脚本吗?在Linux上,需要使用sudo绑定到端口0到1024(如here所述)。你知道吗

还有一件事,与脚本没有特别的关系,但是看起来你在屏幕截图中使用了awsec2(如果我错了,请纠正我)。如果希望能够从公共internet访问端口80上的实例,则需要确保allow it in the Security Group。我知道这会给第一次使用awsec2的人带来一些困惑,当然对我来说也是。你知道吗

希望这有帮助!你知道吗

相关问题 更多 >