我正尝试在具有Apache和mod_wsgi的CentOS 7服务器上部署Django应用程序。该应用程序正在使用plotly库来创建图形,并使用orca应用程序来将创建的图形导出到图像。我使用集成的Django Web服务器测试了该应用程序-一切正常。因此,我根据官方文档设置了Apache和mod_wsgi。当我连接到Apache时,该应用程序可以运行,但是无法导出图形。浏览器最终出现网关超时错误。我将记录器消息插入创建和导出图形的代码中。代码一直运行到这一行:
static_image_bytes = plotly.io.to_image(figure, format='png', width=800, height=450)
此行应运行本地Orca应用程序,并将figure
对象转换为PNG图像字节。 Orca需要X11显示服务器,并且安装的CentOS没有GUI。我正在使用Xvfb来仿真X11(根据Orca的github页面)。 Orca应用程序是从github下载的AppImage。
/ bin / orca
#!/bin/bash
echo "`date` - ORCA STARTING with $@" >> /tmp/orca.log
xvfb-run /usr/u/s/orca-1.2.1-x86_64.AppImage "$@"
echo "`date` - ORCA FINISHED" >> /tmp/orca.log
此外,我尝试使用以下方法将/bin/orca
直接链接到AppImage:
ln -s /usr/u/s/orca-1.2.1-x86_64.AppImage /bin/orca
并将此行添加到我的代码中:
plotly.io.orca.config.use_xvfb = True
Apache error_log:
[Thu Jul 11 14:15:27.353433 2019] [wsgi:info] [pid 6289] mod_wsgi (pid=6289): Attach interpreter ''.
[Thu Jul 11 14:15:27.356811 2019] [wsgi:info] [pid 6290] mod_wsgi (pid=6290): Attach interpreter ''.
[Thu Jul 11 14:15:27.373538 2019] [wsgi:info] [pid 6282] mod_wsgi (pid=6282, process='myapp', application=''): Loading Python script file '/usr/u/s/myapp/myapp/wsgi.py'.
[Thu Jul 11 14:15:27.380468 2019] [wsgi:info] [pid 6285] mod_wsgi (pid=6285): Adding '/usr/u/s/myapp' to path.
[Thu Jul 11 14:15:27.400423 2019] [wsgi:info] [pid 6283] mod_wsgi (pid=6283): Adding '/usr/u/s/myapp' to path.
[Thu Jul 11 14:15:27.401219 2019] [wsgi:info] [pid 6283] mod_wsgi (pid=6283, process='myapp', application=''): Loading Python script file '/usr/u/s/myapp/myapp/wsgi.py'.
[Thu Jul 11 14:15:27.419272 2019] [wsgi:info] [pid 6284] mod_wsgi (pid=6284): Adding '/usr/u/s/myapp' to path.
[Thu Jul 11 14:15:27.420060 2019] [wsgi:info] [pid 6284] mod_wsgi (pid=6284, process='myapp', application=''): Loading Python script file '/usr/u/s/myapp/myapp/wsgi.py'.
[Thu Jul 11 14:15:27.422329 2019] [wsgi:info] [pid 6285] mod_wsgi (pid=6285, process='myapp', application=''): Loading Python script file '/usr/u/s/myapp/myapp/wsgi.py'.
[Thu Jul 11 14:15:33.050402 2019] [wsgi:info] [pid 6419] mod_wsgi (pid=6419): Initializing Python.
[Thu Jul 11 14:15:33.077239 2019] [wsgi:info] [pid 6419] mod_wsgi (pid=6419): Attach interpreter ''.
[Thu Jul 11 14:25:38.116842 2019] [wsgi:error] [pid 6287] [client 192.168.1.12:57406] Timeout when reading response headers from daemon process 'myapp': /usr/u/s/myapp/myapp/wsgi.py, referer: http://192.168.1.13/myapp/reports/new/
[Thu Jul 11 14:25:38.116918 2019] [reqtimeout:info] [pid 6287] [client 192.168.1.12:57406] AH01382: Request body read timeout
Apache httpd.conf
LogLevel info
TimeOut 600
LoadModule wsgi_module modules/mod_wsgi.so
WSGISocketPrefix /var/run/httpd/wsgi
WSGIDaemonProcess myapp python-home=/usr/u/s/env/myapp python-path=/usr/u/s/myapp threads=1 processes=32
WSGIScriptAlias /myapp /usr/u/s/myapp/myapp/wsgi.py process-group=myapp application-group=%{GLOBAL}
<Directory /usr/u/s/myapp>
Require all granted
</Directory>
SELinux设置为许可模式。
我搜索并搜索了stackoverflow数小时,以尝试各种针对mod_wsgi的解决方案和配置,但似乎没有任何改变。请帮忙。谢谢你的想法。
答案 0 :(得分:1)
我不知道以下内容是否可以解决OP问题,但以防万一它对我添加一些上下文的人有所帮助(我不确定OP上面的评论是什么意思)。
我竭尽全力试图使Google Python Client Dialogflow库在WSGI和SElinux下在Apache下工作。我指责SElinux,但是 Deepak Kumar 的上述评论为我提供了解决方案。
将以下行添加到WSGI Apache配置中
WSGIApplicationGroup %{GLOBAL}
根据建议here.