0

I am using apache2 to try and connect to my django application. I have the django app located in myfolder which I am running from the same location as the manage.py with gunicorn myfolder.wsgi -b unix:/home/user/myfolder/web.sock. From what I can see, this works and is waiting for a connection:

[2023-05-02 18:02:10 +0100] [4042470] [INFO] Starting gunicorn 20.0.4                                                                                                                                                            
[2023-05-02 18:02:10 +0100] [4042470] [INFO] Listening at: unix:/home/user/myfolder/web.sock (4042470)                                                                                                                         
[2023-05-02 18:02:10 +0100] [4042470] [INFO] Using worker: sync                                                                                                                                                                  
[2023-05-02 18:02:10 +0100] [4042472] [INFO] Booting worker with pid: 4042472

I have my .htaccess file setup with

RequestHeader set Host expr=%{HTTP_HOST}                                                                                                                                                                                         
RequestHeader set X-Forwarded-For expr=%{REMOTE_ADDR}                                                                                                                                                                            
RequestHeader set X-Forwarded-Proto expr=%{REQUEST_SCHEME}                                                                                                                                                                       
RequestHeader set X-Real-IP expr=%{REMOTE_ADDR}                                                                                                                                                                                  
RewriteRule ^(.*)$ unix:/home/user/myfolder/web.sock|http://example.com/$1 [P,NE,L,QSA]

but for some reason, when I connect to example.com, I don't get connected to the gunicorn instance.

The apache2 logs say

[Tue May 02 18:02:28.396785 2023] [proxy:error] [pid 3731828] (111)Connection refused: AH02454: HTTP: attempt to connect to Unix domain socket /home/user/myfolder/web.sock (*) failed
[Tue May 02 18:02:28.396907 2023] [proxy_http:error] [pid 3731828] [client xxx.xxx.x.xx:54462] AH01114: HTTP: failed to make connection to backend: httpd-UDS

I have confirmed that the web.sock file is created in the target location and I have full permissions over it, so this isn't the same problem as Gunicorn with unix socket not working gives 502 bad gateway.

TLDR: why can't I connect to my gunicorn instance through apache2 using unix sockets?

incarnadine
  • 658
  • 7
  • 19

0 Answers0