PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, March 17, 2022

[FIXED] PhpMyAdmin wrong display in Nginx using reverse proxy

 March 17, 2022     nginx, phpmyadmin, reverse-proxy     No comments   

Issue

  • I am running a NodeJS application in Nginx with a reverse proxy to port 3000
  • PhpMyAdmin is configured and apparently runs in /phpmyadmin
  • /etc/nginx/sites-available/default is configured like this:
server {
    listen 80;
    listen [::]:80;

    root /var/www/html;
    index index.php index.html index.htm index.nginx-debian.html;

    server_name localhost mywebsite.com www.mywebsite.com;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location / {
        proxy_pass http://localhost:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_cache_bypass $http_upgrade;
    }

    location /phpmyadmin {
        root /var/www/html/phpmyadmin/;
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; 
    }
}

I managed to make all work as I wanted, but PhpMyAdmin has a bad display:

enter image description here

Before setting the reverse proxy in that file, PhpMyAdmin ran perfect. I assume there is something I missed in default file.
Any ideas? Thanks


To Ivan Shatsky's Response: @IvanShatsky

I tried substituting with your code, but it downloads a file (it does not read .php files) - So, I added few more lines:

location ^~ /phpmyadmin {
    index index.php;
    try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
    
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

The result is the same before.
When I check the resources of the network, this is what happens: enter image description here

I have performed chmod 777 -R /var/www/html/phpmyadmin but no changes. Would I need to have https? - I am currently trying on http.


Solution

I wonder how it is running at all. Assuming your phpMyAdmin located in the /var/www/html/phpmyadmin directory, try this:

location /phpmyadmin {
    index index.php;
    try_files $uri $uri/ /phpmyadmin/index.php$is_args$args;
}


Answered By - Ivan Shatsky
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,248,260

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing