1

I want to use nginx as a reverse proxy for multiple apps (in docker). They exist in separate directories in the nginx container: /var/www/app1, /var/www/app2, etc.

My default.conf:

resolver 127.0.0.11 valid=15s;

server {
  listen 80;
  server_name www.example.com example.com;
  set $upstream phpmyadmin:9000;

  location ^~ /phpmyadmin {
   #alias /var/www/html/;                 # <----- this works
    alias /var/www/phpmyadmin/;
    index index.php;
    location ~ \.php$ {
      try_files     $uri = 404;
      fastcgi_pass  $upstream;
      include       fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $request_filename;
    }
  }

}

If I mount the docker app (phpmyadmin) in /var/www/html/ then the above nginx config works.

But what I really want is to mount it in /var/www/phpmyadmin/. When I do that I get errors:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

lonix
  • 896
  • 10
  • 23
  • Have you tried `root /var/www;` instead of `alias /var/www/phpmyadmin/;`? – Richard Smith Oct 20 '19 at 10:21
  • @RichardSmith Yeah thought of that, doesn't make a difference unfortunately (same error). So you believe it looks ok? If so then it must be a problem with the app itself (phpmyadmin) or the docker network... which would be weird because it works when I use `/var/www/html/` as the mount point. – lonix Oct 20 '19 at 10:46
  • @RichardSmith Found the problem... the incorrect uri was being used because of the prefix. Added answer below. Thanks for your advice. – lonix Oct 21 '19 at 08:53

1 Answers1

0

Strip prefix from $fastcgi_script_name:

fastcgi_split_path_info ^\/phpmyadmin\/(.+\.php)(.*)$;

Then use it:

fastcgi_param SCRIPT_FILENAME $fastcgi_script_name;
lonix
  • 896
  • 10
  • 23