简体   繁体   中英

Django with Apache and mod_wsgi: Timeout error

I'm trying to deploy Django application on a CentOS 7 server with Apache and mod_wsgi. The application is using plotly library to create graphs and plotly is using orca application to export created graph to image. I tested the application using the integrated django web server - everything works perfectly. So I set up Apache and mod_wsgi according official documentation. When I connect to Apache the application works, but it is not possible to export graphs. Browser ends up with Gateway Timeout Error. I inserted logger messages to the code which creates and exports graphs. The code runs until this line:

static_image_bytes = plotly.io.to_image(figure, format='png', width=800, height=450) 

This line should run local Orca application and translate figure object to PNG image bytes. Orca requires X11 display server and CentOS is installed without GUI. I'm using Xvfb to emulate X11 (according to Orca's github page). Orca application is an AppImage downloaded from github.

/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  

Also, I have tried to link /bin/orca directly to AppImage using:

ln -s /usr/u/s/orca-1.2.1-x86_64.AppImage /bin/orca

and adding this line to my code:

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 is set to Permissive mode.

I googled and searched stackoverflow for hours trying various solutions and configurations for mod_wsgi, but none of them seems to change anything. Please help. Thanks for any ideas.

I don't know if the following resolves the OP question, but just in case it is helpful to someone I am adding some context (I am not sure what does OP's comment above mean).

I was pulling my hairs trying to make Google Python Client Dialogflow library working under Apache with WSGI and SElinux. I was blaming SElinux, but the comment above by Deepak Kumar gave me a solution.

Add to WSGI Apache config the line

WSGIApplicationGroup %{GLOBAL}

as suggested here.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM