简体   繁体   中英

Deploying Python app on cPanel via CGI - SuExec & 500 error

I have the following CGI script which launches a Flask web application. However all I get is a 500 Internal Server Error

#!/home/xxx/public_html/cgi-bin/venv/bin/python
import site
site.addsitedir("/home/xxx/public_html/cgi-bin/venv/lib/python2.7/site-packages")

from wsgiref.handlers import CGIHandler
from app import app

CGIHandler().run(app)

I get the following errors in Apache's error_log :

[Fri Jan 27 09:53:18.052981 2017] [cgi:error] [pid 20660] [client aa.bb.cc.dd:58331] AH01215: suexec policy violation: see suexec log for more details: /home/xxx/public_html/cgi-bin/app.cgi, referer: http://xxx.io/

[Fri Jan 27 09:53:18.053176 2017] [cgi:error] [pid 20660] [client aa.bb.cc.dd:58331] End of script output before headers: app.cgi, referer: http://xxx.io/

And the following error in suexec_log :

[2017-01-27 09:53:18]: uid: (522/xxx) gid: (534/xxx) cmd: app.cgi

[2017-01-27 09:53:18]: (2)No such file or directory: exec failed (app.cgi)

All the files should be in all the right places. Not sure how to proceed with debugging. If it helps, I do have root access to this server.

Two problems:

  1. The .cgi file contained Windows line endings
    • Solved by :set ff=unix in Vim
  2. The python interpreter in my virtualenv was not set as executable

Once I solved those, it works like a charm!

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