Search code examples
djangolinuxnginxgunicornpgadmin-4

setting up pgadmin4 on a VPS running ubuntu. Configuring it from nginx


The final instructions for configuring nginx for pgadmin4 read:

location / {
        proxy_pass http://unix:/tmp/pgadmin4.sock;
        include proxy_params;
    }

but I already had that proxy_pass configured for this:

location @proxy_to_app {
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_pass http://app_server; <----HERE
    }

the app_server refers to:

upstream app_server {  
  server unix:/home/boards/run/gunicorn.sock fail_timeout=0;
}

so, the proxy_pass is sort-of already taken. The instructions come from digitalocean

UPDATE: I had already tried adding this, which I know it is correct:

location / {
        proxy_pass http://unix:/tmp/pgadmin4.sock;
        include proxy_params;
    }

but there is one more thing to do for nginx to communicate with gunicorn, otherwise it will give me the 502 bad gateway error, namely:

gunicorn --bind unix:/tmp/pgadmin4.sock --workers=13 --threads=25 --chdir ~/environments/my_env/lib/python3.10/site-packages/pgadmin pgAdmin:app

I will create a separate question in another post in order to honor the answer given, but the issue is still unresolved as there is this extra binding address to be done. l


Solution

  • You need to set up a separate location block in your Nginx configuration for pgAdmin4 because you already have a proxy_pass directive pointing to another application.

    To avoid conflicts, you can set up pgAdmin4 under a different URI if you want to access pgAdmin4 via your domain like yourdomain.com/pgadmin like below:

    location /pgadmin/ {
        proxy_pass http://unix:/tmp/pgadmin4.sock;
        include proxy_params;
    }
    

    Make sure to adjust the URI /pgadmin/ as per your preference.

    After making this change you need to restart your nginx server. But before restarting it's a good practice to test the configuration for any syntax errors sudo nginx -t

    sudo nginx -t    
    sudo systemctl restart nginx
    

    Now, For testing open your web browser and check if the URL you set is working with pgadmin (e.g., yourdomain.com/pgadmin)

    Note: If you don't have domain setup in your Nginx server you can try with your IP address (e.g., yourServerIP/pgadmin)