mod_wsgi can't connect to postgresql server

213 views
Skip to first unread message

Robert Currier

unread,
Mar 12, 2015, 5:23:09 PM3/12/15
to mod...@googlegroups.com
Running CentOS 7 on a Digital Ocean droplet. The latest version of mod_wsgi is installed. From the command line I can do:
python app.py and then connect to port 5000. Using psycopg2 I am able to talk to my postgresql db. This works perfectly from within Flask and from pure command line scripts like ./bulk_load_psgq r 5000 (autopopulates a pgsql db)

But when I try to connect via mod_wsgi at http://hostname/app_dir/ I fail with:

[Thu Mar 12 16:47:50.442356 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] File "/var/www/wsgi/gcoos_itag/app/iTAG.py", line 76, in home
[Thu Mar 12 16:47:50.442462 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] my_receivers = get_my_receivers()
[Thu Mar 12 16:47:50.442479 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] File "/var/www/wsgi/gcoos_itag/app/gcoos_utils.py", line 45, in get_my_receivers
[Thu Mar 12 16:47:50.442570 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] conn = psycopg2.connect("dbname=itag user=postgres password=xxxxxxxxxxx")
[Thu Mar 12 16:47:50.442588 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] File "/usr/lib64/python2.7/site-packages/psycopg2/__init__.py", line 164, in connect
[Thu Mar 12 16:47:50.442702 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] conn = _connect(dsn, connection_factory=connection_factory, async=async)
[Thu Mar 12 16:47:50.442730 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] OperationalError: could not connect to server: No such file or directory
[Thu Mar 12 16:47:50.442737 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] \tIs the server running locally and accepting
[Thu Mar 12 16:47:50.442741 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658] \tconnections on Unix domain socket "/tmp/.s.PGSQL.5432"?
[Thu Mar 12 16:47:50.442746 2015] [wsgi:error] [pid 4990] [remote 71.226.81.79:18658]

My tmp file is present and EVERYTHING else about postgresql works fine. I've tried changing the WSGIDaemonProcess user to postgres, and have diddled with the pg_hba.conf file to no avail. This EXACT setup is working perfectly on my Mac OS X box... 

Why would I be able to see the postgres server in all cases except through mod_wsgi?  All help appreciated -- this is driving me crazy.

Thanks,

Bob Currier

Jason Garber

unread,
Mar 13, 2015, 5:38:58 PM3/13/15
to mod...@googlegroups.com
Hi Bob,

My first guess is that you have SELinux turned on.

Run:
sestatus

If it is off, then no idea.
If it is on, then try disabling to see if that works (note: may need to restart apache)

Once you have determined that, perhaps you can modify your selinux policy to allow for this connection so you don't have to disable it.

Thanks!
Jason


--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages