Today I learned a incredibly useful trick for debugging web applications that don’t use standard TCP/IP networking. While we usually think of curl as a tool for fetching data over http:// or https:// via a port like 80 or 443, it is also fully capable of communicating over Unix Domain Sockets.
Why use Unix sockets?
You can use Unix sockets instead of TCP to proxy application servers. Sockets are often faster and more secure for local inter-process communication because they avoid the overhead of the network stack and can be protected by standard file permissions.
The challenge arises when you want to test the application server directly without going through the public-facing proxy. That is where this curl command comes in.
The Command
To request a page from a service listening on a Unix socket, use the --unix-socket flag followed by the path to the socket file:
curl --unix-socket /var/www/app/app.sock http://localhost/
The --unix-socket flag tells curl to ignore the standard DNS resolution for the hostname and instead connect directly to the file path provided, which in this case is /var/www/app/app.sock.
The http://localhost/ part of the command is still required because curl needs to know which protocol to use and what to put in the Host header of the HTTP request. Even though the data is traveling through a file on your hard drive rather than a network card, the application server still expects a valid HTTP request format.
This is a lifesaver for troubleshooting “502 Bad Gateway” errors. By bypasssing Nginx and hitting the socket directly, you can determine if the issue lies with the application server itself or the proxy configuration. If the command above returns the expected HTML, you know your backend is healthy and the problem is likely in your nginx .conf file.

