Serving multiple socket using gunicorn and Nginx cause a NotFound error

Solution 1:

The second is accessible, and the "Not found" error is returned by the app server on that socket.

Most likely this happens because nginx will forward a request to /app2loc to your second application server.

Change the proxy_pass for app2 to:

location /app2loc/ {
    proxy_pass http://app2/;
}

upstream app2 {
    server unix:/var/www/html/app2/app.sock;
}

The extra / at end of proxy_pass makes nginx strip the app2loc prefix from the URI passed to upstream.

Remember also to configure your application's base URL to include the app2loc prefix.