Skip to content

Can't get phppgadmin to work with nginx

Hi, I'm trying to setup a local PHP development environment with Nginx, PostgreSQL and phpPgAdmin. This is my configuration file for Nginx:

user http;
worker_processes auto;
worker_cpu_affinity auto;
pcre_jit on;

events {
    worker_connections 2048;
}

http {
    error_log /var/log/nginx/error.log;
    include mime.types;
    default_type application/octet-stream;
    sendfile on;
    tcp_nopush on;
    aio threads;
    types_hash_max_size 4096;
    server_tokens off; # Security: Disables nginx version in error messages and in the “Server” response header field.
    charset utf-8; # Force usage of UTF-8
    include sites-enabled/*; # See Server blocks
    server {
        listen 80;
        listen [::1]:80;
        server_name localhost;
        root /srv/http/dev;
        location / {
            index index.php index.html index.htm;
        }
        include php.conf;
    }
}

I created a separate configuration for php-fpm, as suggested by the Archwiki, which looks like this:

location ~ \.php$ {
    try_files $uri $document_root$fastcgi_script_name =404;
    fastcgi_pass unix:/run/php-fpm/php-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi.conf;

    # prevention for httpoxy vulnerability: https://httpoxy.org/
    fastcgi_param HTTP_PROXY "";
}

and the file for phppgadmin under /etc/nginx/sites-available/ as follows:

server {
    server_name phppgadmin.dev;
    root /usr/share/webapps/phppgadmin;
    index index.php;
    include php.conf;
}

Typing http://localhost in the browser works as expected: I can run any PHP file with no problem. However, if I type phppgadmin.dev I get "This site can't be reached" from Chromium. I added the phppgadmin.dev entry to the /etc/hosts file and I can ping it successfully from my terminal. What am I doing wrong?

13 points8 comments
Open on Reddit
About this post
Posted
Archived
Score
13 · 100% up
Kind
Text
ID
aa0mt6

Author

7
posts
149
comments
1
media
View profile

8 comments

The TLD .dev is managed by google and they added it to the hsts preload list. So your browser is automatically trying to connect to :443 (Which you don't have enabled in nginx?)

https://ma.ttias.be/chrome-force-dev-domains-https-via-preloaded-hsts/

3 points

Thanks, I changed the server block to this

server {
    server_name phppgadmin.localhost;
    root /usr/share/webapps/phppgadmin;
    index index.php;
    include php.conf;
}

but still doesn't work, but in a different way. If I type phppgadmin.localhost in the browser, nginx behaves as if I had typed just localhost.

1 points

What are the other relevant server blocks, especially the one you think is being used? Nginx picks one in this order based on the hostname in the request:

  1. exact name
  2. longest wildcard name starting with an asterisk, e.g. “*.example.org”
  3. longest wildcard name ending with an asterisk, e.g. “mail.*"
  4. first matching regular expression (in order of appearance in a configuration file)

Source: http://nginx.org/en/docs/http/server_names.html

1 points

I'm not sure about how the localhost name gets resolved, but is it possible to use subdomains to localhost? As far as I know, it shouldn't be and that's why you can't listen on a localhost subdomain. The solution would be to simply listen on the localhost (and use different ports if you need different services).

1 points

OT: Why not pgadmin?

1 points

Because I feel phppgadmin is closer to phpmyadmin, which I'm already familiar with. Also pgadmin pulls down so many Python dependencies for a total installed size of ~200 MB. Phppgadmin is only a few megabytes.

1 points

Keyboard shortcuts

Move and act

jork
Next / previous post or comment
Enteroro
Open the post
f
Open the media viewer
s
Save
h
Hide (the toast has Undo)
Tab
Right after an action: the toast's Undo
x
Collapse the comment
v
Next layout: cards, compact, grid

Go to

/
Search
gthenh
Home
gthena
All
gthens
Subreddits
gthenl
Library
?
This list
Esc
Close a menu or this list

In the viewer

←or→
Previous / next file
↑or↓
Previous / next post
korj
Previous / next post
Space
Play / pause
m
Mute
z
Zoom
s
Save
o
Open the post (on its own page: back to it)
Esc
Close

Keys do nothing while you type in a box.