Apache &引用;OSError:[Errno 88]非套接字上的套接字操作";用触发器

Apache &引用;OSError:[Errno 88]非套接字上的套接字操作";用触发器,apache,sockets,flask,fastcgi,mod-fcgid,Apache,Sockets,Flask,Fastcgi,Mod Fcgid,在尝试将Flask应用程序部署到LAMP服务器时,我从FastCGI/WSGI网关收到一个错误,该网关使我的应用程序能够使用FastCGI协议 ~/minimal/run.py Apache配置文件的相关部分,即/etc/httpd/conf/httpd.conf: <VirtualHost *:80> ScriptAlias / /home/apps/minimal/run.py ErrorLog /var/log/httpd/error_log </Virt

在尝试将Flask应用程序部署到LAMP服务器时,我从FastCGI/WSGI网关收到一个错误,该网关使我的应用程序能够使用FastCGI协议

~/minimal/run.py

Apache配置文件的相关部分,即
/etc/httpd/conf/httpd.conf

<VirtualHost *:80>
    ScriptAlias / /home/apps/minimal/run.py
    ErrorLog /var/log/httpd/error_log
</VirtualHost>
错误输出:

[apps@kernod0 ~]$ sudo cat /var/log/httpd/error_log
[Wed Aug 16 20:47:24 2017] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Aug 16 20:47:24 2017] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 16 20:47:24 2017] [notice] Digest: done
[Wed Aug 16 20:47:24 2017] [notice] Apache/2.2.15 (Unix) DAV/2 mod_fcgid/2.3.9 configured -- resuming normal operations
[Wed Aug 16 20:47:33 2017] [error] [client 100.116.226.182]  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] Traceback (most recent call last):
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/run.py", line 11, in <module>
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] app.run()
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/flask/app.py", line 841, in run
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] run_simple(host, port, self, **options)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 739, in run_simple
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] inner()
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 699, in inner
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] fd=fd)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 593, in make_server
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] passthrough_errors, ssl_context, fd=fd)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 504, in __init__
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] HTTPServer.__init__(self, (host, int(port)), handler)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/usr/lib64/python2.6/SocketServer.py", line 412, in __init__
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] self.server_bind()
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/usr/lib64/python2.6/BaseHTTPServer.py", line 108, in server_bind
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] SocketServer.TCPServer.server_bind(self)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/usr/lib64/python2.6/SocketServer.py", line 423, in server_bind
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] self.socket.bind(self.server_address)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "<string>", line 1, in bind
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] socket
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] .
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] error
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] : 
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] [Errno 98] Address already in use
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] 
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] Premature end of script headers: run.py
[Wed Aug 16 20:48:33 2017] [warn] [client 100.116.226.182] Timeout waiting for output from CGI script /home/apps/minimal/run.py
[Wed Aug 16 20:48:33 2017] [error] [client 100.116.226.182] Script timed out before returning headers: run.py
[Wed Aug 16 20:49:33 2017] [warn] [client 100.116.226.182] Timeout waiting for output from CGI script /home/apps/minimal/run.py
[apps@kernod0~]$sudo cat/var/log/httpd/error\u log
【2017年8月16日星期三20:47:24】【通知】已启用suEXEC机制(包装器:/usr/sbin/suEXEC)
[2017年8月16日星期三20:47:24][通知]摘要:为摘要身份验证生成机密。。。
[2017年8月16日星期三20:47:24][通知]摘要:完成
[2017年8月16日星期三20:47:24][注意]已配置Apache/2.2.15(Unix)DAV/2 mod_fcgid/2.3.9--恢复正常操作
[2017年8月16日星期三20:47:33][error][client 100.116.226.182]*正在运行http://127.0.0.1:5000/ (按CTRL+C退出)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]回溯(最近一次通话):
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/home/apps/minimal/run.py”,第11行,在
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]app.run()
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/home/apps/minimal/flask/lib/python2.6/site packages/flask/app.py”,第841行,运行中
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]运行简单(主机、端口、自身,**选项)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/home/apps/minimal/flask/lib/python2.6/site packages/werkzeug/serving.py”,第739行,简单运行
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]内部()
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/home/apps/minimal/flask/lib/python2.6/site packages/werkzeug/service.py”,第699行,内页
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]fd=fd)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/home/apps/minimal/flask/lib/python2.6/site packages/werkzeug/service.py”,第593行,在make_服务器中
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]passthrough_错误,ssl_上下文,fd=fd)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/home/apps/minimal/flask/lib/python2.6/site packages/werkzeug/service.py”,第504行,在__
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]HTTPServer.\uuuuu init\uuuuu(self,(主机,int(端口)),处理程序)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/usr/lib64/python2.6/SocketServer.py”,第412行,在__
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]self.server_bind()
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/usr/lib64/python2.6/BaseHTTPServer.py”,第108行,在服务器绑定中
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]SocketServer.TCPServer.server_bind(self)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“/usr/lib64/python2.6/SocketServer.py”,第423行,在服务器绑定中
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]self.socket.bind(self.server_地址)
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]文件“”,第1行,处于绑定状态
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]套接字
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]。
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]错误
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]:
[Wed Aug 16 20:47:37 2017][error][client 100.116.226.190][Errno 98]地址已在使用中
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]
[2017年8月16日星期三20:47:37][error][client 100.116.226.190]脚本头过早结束:run.py
[2017年8月16日星期三20:48:33][warn][client 100.116.226.182]等待CGI脚本/home/apps/minimal/run.py输出超时
[2017年8月16日星期三20:48:33][error][client 100.116.226.182]返回标题前脚本超时:run.py
[2017年8月16日星期三20:49:33][warn][client 100.116.226.182]等待CGI脚本/home/apps/minimal/run.py输出超时

无法从终端运行fastcgi脚本。这个脚本应该由Apache执行。通常,您在Apache配置文件中的
ScriptAlias
指令中配置了它。

通常,您应该使用
mod\u fastcgi
和类似的配置:

<VirtualHost *:8091>
  ServerName helloworld.local
  DocumentRoot /home/fe/work/flipflop
  FastCgiServer /home/fe/work/flipflop/run.py
  ScriptAlias / /home/fe/work/flipflop/run.py
    <Location />
      Options none
    </Location>
</VirtualHost>

ServerName helloworld.local
文档根/主/fe/工作/触发器
FastCgiServer/home/fe/work/flipflop/run.py
ScriptAlias//home/fe/work/flipflop/run.py
选项无
因此,它将使您的脚本以FastCgi的形式运行,但我不熟悉触发器,无法使其工作


但如果您不限于
flipflop
,您可以使用
uwsgi
运行应用程序,
mod_wsgi
使用
Apache
运行应用程序(请参阅中的更多详细信息),或者使用
Flask Script
runserver
命令在调试服务器中运行应用程序(请参见《第一件事》中的示例,看起来您已经有一些应用程序在端口5000上运行/侦听。 您可能希望使用
sudosockstat | grep5000
查找哪个,然后配置Apache,或者使用
localhost:5000
终止进程/服务

其次,您的虚拟主机似乎未被考虑/未完全配置
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'hello, world'

if __name__ == '__main__':
    app.run()
[apps@kernod0 ~]$ sudo cat /var/log/httpd/error_log
[Wed Aug 16 20:47:24 2017] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)
[Wed Aug 16 20:47:24 2017] [notice] Digest: generating secret for digest authentication ...
[Wed Aug 16 20:47:24 2017] [notice] Digest: done
[Wed Aug 16 20:47:24 2017] [notice] Apache/2.2.15 (Unix) DAV/2 mod_fcgid/2.3.9 configured -- resuming normal operations
[Wed Aug 16 20:47:33 2017] [error] [client 100.116.226.182]  * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] Traceback (most recent call last):
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/run.py", line 11, in <module>
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] app.run()
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/flask/app.py", line 841, in run
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] run_simple(host, port, self, **options)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 739, in run_simple
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] inner()
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 699, in inner
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] fd=fd)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 593, in make_server
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] passthrough_errors, ssl_context, fd=fd)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/home/apps/minimal/flask/lib/python2.6/site-packages/werkzeug/serving.py", line 504, in __init__
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] HTTPServer.__init__(self, (host, int(port)), handler)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/usr/lib64/python2.6/SocketServer.py", line 412, in __init__
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] self.server_bind()
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/usr/lib64/python2.6/BaseHTTPServer.py", line 108, in server_bind
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] SocketServer.TCPServer.server_bind(self)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "/usr/lib64/python2.6/SocketServer.py", line 423, in server_bind
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]     
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] self.socket.bind(self.server_address)
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190]   File "<string>", line 1, in bind
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] socket
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] .
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] error
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] : 
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] [Errno 98] Address already in use
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] 
[Wed Aug 16 20:47:37 2017] [error] [client 100.116.226.190] Premature end of script headers: run.py
[Wed Aug 16 20:48:33 2017] [warn] [client 100.116.226.182] Timeout waiting for output from CGI script /home/apps/minimal/run.py
[Wed Aug 16 20:48:33 2017] [error] [client 100.116.226.182] Script timed out before returning headers: run.py
[Wed Aug 16 20:49:33 2017] [warn] [client 100.116.226.182] Timeout waiting for output from CGI script /home/apps/minimal/run.py
<VirtualHost *:8091>
  ServerName helloworld.local
  DocumentRoot /home/fe/work/flipflop
  FastCgiServer /home/fe/work/flipflop/run.py
  ScriptAlias / /home/fe/work/flipflop/run.py
    <Location />
      Options none
    </Location>
</VirtualHost>
sudo -EH pip2 install virtualenvwrapper
source /usr/local/bin/virtualenvwrapper.sh
mkvirtualenv minimal
pip install -U flask flup
sudo apt-get install apache2
sudo apt-get install libapache2-mod-fastcgi
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'hello, world'
#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)

activate_this = '/home/some_user/.virtualenvs/minimal/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))

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

from flup.server.fcgi import WSGIServer
from run import app

if __name__ == '__main__':
    WSGIServer(app).run()
sudo chmod +x minimal.fcgi
FastCgiServer /var/www/minimal/minimal.fcgi -idle-timeout 300 -processes 5

<VirtualHost *:80>
    ServerName YOUR_IP_ADDRESS
    DocumentRoot /var/www/minimal/

    AddHandler fastcgi-script fcgi
    ScriptAlias / /var/www/minimal/minimal.fcgi/

    <Location />
        SetHandler fastcgi-script
    </Location>
</VirtualHost>
sudo a2ensite minimal.conf
sudo chown -R www-data:www-data /var/www/
sudo /etc/init.d/apache2 restart 
[Thu Aug 24 16:33:09.354544 2017] [mpm_event:notice] [pid 17375:tid 139752788969344] AH00491: caught SIGTERM, shutting down
[Thu Aug 24 16:33:10.414829 2017] [mpm_event:notice] [pid 17548:tid 139700962228096] AH00489: Apache/2.4.18 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
[Thu Aug 24 16:33:10.415033 2017] [core:notice] [pid 17548:tid 139700962228096] AH00094: Command line: '/usr/sbin/apache2'
[Thu Aug 24 16:33:10.415651 2017] [:notice] [pid 17551:tid 139700962228096] FastCGI: process manager initialized (pid 17551)
[Thu Aug 24 16:33:10.416135 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17556)
[Thu Aug 24 16:33:11.416571 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17618)
[Thu Aug 24 16:33:12.422058 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17643)
[Thu Aug 24 16:33:13.422763 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17651)
[Thu Aug 24 16:33:14.423536 2017] [:warn] [pid 17551:tid 139700962228096] FastCGI: server "/var/www/minimal/minimal.fcgi" started (pid 17659)