nginxweb-development-serveradminer

Nginx causes problems with access to the Adminer SQL web administrator


I'm new to nginx.
I have a php server listening on 127.0.0.1:82 (started from adminer firectory so it gives adminer.php when it is requested) and nginx on 127.0.0.1:80. I need to redirect any /admin request to Adminer, meaning to PHP server. When I try localhost:82/aminer.php, it works just fine. But when i try it via nginx (localhost:80/admin/aminer.php), only start page works. When I try to authorize, the HTTP response I get has code 403 (access denied). GUI shows no errors like "Login failed for user 'Admin'" if I input the wrong password, it just resets the page. enter image description here

I can't figure the problem.
Here is my nginx configuration file:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
    worker_connections 768;
    # multi_accept on;
}

http
{
    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;
    
    #include /etc/nginx/conf.d/*.conf;
    #include /etc/nginx/sites-enabled/*;    
    
    server
    {
        listen localhost:80;
        
        location /admin/
        {
            proxy_pass http://localhost:82/;
            proxy_no_cache 1;
        }
    }
    

    ##
    # Basic Settings
    ##

    #sendfile on;
    #tcp_nopush on;
    #tcp_nodelay on;
    #keepalive_timeout 65;
    #types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    #include /etc/nginx/mime.types;
    #default_type application/octet-stream;

    ##
    # SSL Settings
    ##

    #ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3; # Dropping SSLv3, ref: POODLE
    #ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    ##
    # Gzip Settings
    ##

    gzip on;

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##
}

This is how I raise my PHP server:
enter image description here

Ypu can see here that adminer works directly on :82 port:
enter image description here

Logs screenshots:
access.log:
enter image description here

error.log:
enter image description here

php server log:
enter image description here


Solution

  • Got the answer on russian stackoverflow:

    The problem occured because the first localhost/admin/ call redirects the request on localhost:28/adminer.php, but any request or action on that page will be redirected to localhost:28/admin/adminer.php which is invalid.

    To fix this, the PHP server has to start one directory above (so that the file adminer.php could be reqched by localhost:28/admin/adminer.php.
    Also, the line proxy_pass http://localhost:82/; must be replaced with proxy_pass http://localhost:82; in nginx configuration file.