Re: pgadmin4 running behind nginx

From: Dan Davis <dansmood(at)gmail(dot)com>
To: jbiskofski <jbiskofski(at)gmail(dot)com>
Cc: Dave Page <dpage(at)pgadmin(dot)org>, Ashesh Vashi <ashesh(dot)vashi(at)enterprisedb(dot)com>, Harshal Dhumal <harshal(dot)dhumal(at)enterprisedb(dot)com>, pgAdmin Support <pgadmin-support(at)postgresql(dot)org>
Subject: Re: pgadmin4 running behind nginx
Date: 2017-02-01 20:53:59
Message-ID: CAFzonYYct+XstFhoM+Kg2c5FF3guzGwNiK9JLuv5YU8ck0xLQQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgadmin-support

Another trick here is to let the back-end know that it is https:

proxy_set_header X-Forwarded-Proto https;

On Wed, Feb 1, 2017 at 12:34 PM, jbiskofski <jbiskofski(at)gmail(dot)com> wrote:

> I Set up my nginx as Harshal suggested and this fixed the problem. Thanks
> for the help!
>
> On Wed, Feb 1, 2017 at 3:37 AM, Dave Page <dpage(at)pgadmin(dot)org> wrote:
>
>>
>>
>> On Wed, Feb 1, 2017 at 10:20 AM, Ashesh Vashi <
>> ashesh(dot)vashi(at)enterprisedb(dot)com> wrote:
>>
>>> On Wed, Feb 1, 2017 at 3:44 PM, Dave Page <dpage(at)pgadmin(dot)org> wrote:
>>>
>>>> On Wed, Feb 1, 2017 at 10:11 AM, Harshal Dhumal
>>>> <harshal(dot)dhumal(at)enterprisedb(dot)com> wrote:
>>>> > Hi,
>>>> >
>>>> > When I setup my machine with below server setup and without
>>>> proxy_redirect I
>>>> > got slightly different behaviour. In my case all redirects were
>>>> failing
>>>> > cause browser was redirecting all request to http while server
>>>> (nginx) was
>>>> > configure to serve only https. I didn't get any intermittent state
>>>> like
>>>> > pgAdmin4 front page was loading but other requests (like css, js) was
>>>> > failing.
>>>> >
>>>> > Issue was when pgAdmin4 app returns redirect (301 /302) response to
>>>> apache
>>>> > and apache to nginx; the nginx was returning redirect location header
>>>> as is
>>>> > (i.e. with http protocol as apache was configured to accept only http)
>>>> >
>>>> > To avoid this I need to rewrite location header at nginx
>>>> (proxy_redirect)
>>>> > before sending it to browser.
>>>> >
>>>> > proxy_set_header X-Real-IP $remote_addr;
>>>> > proxy_set_header X-Forwarded-For $remote_addr;
>>>> > proxy_set_header Host $host;
>>>> > proxy_pass http://127.0.0.1:81;
>>>> > proxy_redirect http:// https://;
>>>> >
>>>> > With above nginx configuration pgAdmin was loading properly.
>>>> >
>>>> > Server setup:
>>>> >
>>>> > Nginx listing at 443 (https only) and forwarding all requests to
>>>> apache at
>>>> > 127.0.0.1:81
>>>> > Apache listing at port 81 (http only) with pgAdmin4 wsgi
>>>>
>>>> Nice - thanks Harshal.
>>>>
>>>> Were you able to see why we're trying to load
>>>> http://127.0.0.1:5050/login?next=%2Fbrowser%2Fbrowser.css ? I can
>>>> reproduce that just by pointing my browser at a dev server (e.g.
>>>> werkzeug). No Apache or nginx needed.
>>>>
>>> I think - I spotted it.
>>>
>>> We've the 'login_required' decorated for the browser_css function.
>>> And, It has been referred in base.html template, which is also used in
>>> the login.html.
>>>
>>> Please try to remove '@login_required' decorator from the 'browser_css'
>>> function, found in the 'web/pgadmin/browser/__init__.py' file.
>>>
>>
>> Good shout - that fixes that problem, but leaves us with an http/500
>> error because browser_css loads per-user preferences. I think we need to
>> conditionally include this block from base.html:
>> <!-- View specified stylesheets -->
>>
>> {% for stylesheet in current_app.stylesheets %}
>> <link type="text/css" rel="stylesheet" href="{{ stylesheet }}">
>>
>> {% endfor %}
>>
>> But I don't have time to investigate further right now as I have to leave
>> for FOSDEM soon.
>>
>> --
>> Dave Page
>> Blog: http://pgsnake.blogspot.com
>> Twitter: @pgsnake
>>
>> EnterpriseDB UK: http://www.enterprisedb.com
>> The Enterprise PostgreSQL Company
>>
>
>

In response to

Responses

Browse pgadmin-support by date

  From Date Subject
Next Message Ronnie Taib 2017-02-02 01:57:26 pgAdmin4 not displaying geometry details nicely (for a GIS table)
Previous Message stancs3 2017-02-01 19:11:37 Re: 4th Try: pgadmin4 install, launch fail