Score:0

nginx how to execute php scripts on "internal" uris?

in flag

I have a problem getting php scripts to execute in internal sites loaded via X-accl-Redirect.. My /etc/nginx/sites-enabled/devdb.easy-ads.com file contains:

server {
        root /srv/http/devdb.easy-ads.com/www;
        index index.html index.htm index.nginx-debian.html index.php;
        server_name devdb.easy-ads.com;
        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }


        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        #       # With php-fpm (or other unix sockets):
                fastcgi_pass unix:/run/php/php8.1-fpm.sock;
        #       # With php-cgi (or other tcp sockets):
        #       fastcgi_pass 127.0.0.1:9000;
        }
        error_page 404 = /index.php;
        location /phpmyadmin_internal {
                internal;
                alias /srv/http/phpmyadmin;
        }
    listen [::]:443 ssl ipv6only=on; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/devdb.easy-ads.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/devdb.easy-ads.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}

and in /srv/http/devdb.easy-ads.com/www/index.php i have:

<?php
header("X-Accel-Redirect: /phpmyadmin_internal/test2.txt");

and everything works great, it loads the file /srv/http/phpmyadmin/test2.txt just as expected. However when I change it to

<?php
header("X-Accel-Redirect: /phpmyadmin_internal/test.php");

it just serves a 404 error, instead of executing /srv/http/phpmyadmin/test.php .. what gives? how can i get it to execute php scripts on internal sites?

(what i THINK is happening, is that it asks php-fpm to load the literal url /phpmyadmin_internal/test.php , not properly giving it a new uri/root-dir before sending it off to php-fpm, but i don't actually know.)

Score:0
in flag

first remove the alias directive for /phpmyadmin_internal, just do:

       location /phpmyadmin_internal {
                internal;
        }

then make a symlink to the target folder like

ln -s '/srv/http/phpmyadmin/' '/srv/http/devdb.easy-ads.com/www/phpmyadmin_internal'

and voila, everything works (-:

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.