• Please be aware: Kaspersky Anti-Virus has been deprecated
    With the upgrade to Plesk Obsidian 18.0.64, "Kaspersky Anti-Virus for Servers" will be automatically removed from the servers it is installed on. We recommend that you migrate to Sophos Anti-Virus for Servers.
  • The Horde webmail has been deprecated. Its complete removal is scheduled for April 2025. For details and recommended actions, see the Feature and Deprecation Plan.
  • We’re working on enhancing the Monitoring feature in Plesk, and we could really use your expertise! If you’re open to sharing your experiences with server and website monitoring or providing feedback, we’d love to have a one-hour online meeting with you.

Resolved a file with no extension will not parse as php

larryk

Regular Pleskian
hello,

i have:
FPM applciation as nginx

php will work fine if you have .php on a file.

BUT what do I need to do to make this url work:

domain.com/file

CURRENTLY, the above url will only display this:

<? echo "test"; ?>

meaning, the browser displays the above text, NOT php command of test

help!!
thanks
 
Hi larryk,

you can try an "alias" definition, as for example:
  1. Name the file "file.php"
  2. Insert
    Code:
    Alias /file "/file.php"
    to the additional http/https - directives at "Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings" and
    Code:
    location /file { alias /file.php; }
    for the additional nginx directive.
 
thanks for the replies... but:

location / {
try_files $uri $uri.php $uri/;
}

gives this error:
Invalid nginx configuration: nginx: [emerg] duplicate location "/" in /var/www/vhosts/system/domain.com/conf/vhost_nginx.conf:1 nginx: configuration file /etc/nginx/nginx.conf test failed

NOTE: yes, that error makes ZERO, zero, 0 since to me :(
NOTE2: i added it ALL BY ITSELF, same error


about the alias,
never heard/saw anything about it (thanks for the info), but technically, I would have unlimited aliases, as I need this situation to work:
domain.com/resort/city/state
or
domain.com/resort/city/state/
or
domain.com/resort/city/state.php

where:
resort is actually php file that does the logic.
city & state are the parameters that get passed into the resort script.

OR maybe /file = is actually the parameter to pass into the index.php script.

Any other ideas?
I've been stuck on this for many, many hours :(
 
Try this Home > Subscriptions > YOUR-DOMAIN.COM > Apache & nginx Settings,

Code:
location ~ \.php$ {
    include fastcgi_params;
    fastcgi_pass unix:/var/run/php5-fpm.sock;
}
 
note:
I will not be using a .php in the URL or file name --- so that would not help.

also, I had thought, by default, installing nginx in plesk ---- all php, fastcgi, php5-fpm, etc. etc. settings/config stuff is ALL DONE for you?

is the above correct?
thanks
 
Hi larryk,

NOTE: yes, that error makes ZERO, zero, 0 since to me
well, in this case, you should consider to have a LOOK at your current domain - specific nginx - configuration, because the "location /" HAS to be configured and due to the fact, that you already have such a location definition, you can't use another one. ;)

In your specific ( now better explained case! ), you could probably use for apache:
Code:
Options +FollowSymLinks -MultiViews -indexes
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1.php [L]

... and for nginx:
Code:
 if (-f $request_filename.php){
set $rule_0 1$rule_0;
}
if ($uri !~ "/$"){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite /(.*) /$1.php last;
}



I still want to mention, that your issue/question has got absolutely nothing to do with Plesk and such questions should be asked at => "Open Topics"
 
Last edited by a moderator:
:)
well, I asked here because I figured it might be some "config" issue

I had made the following changes (based on the above) to this:
location = /resort/(.*)/(.*) {
rewrite /(.*)/(.*) /resort.php last;
}

if (-f $request_filename.php){
set $rule_0 1$rule_0;
}
if ($uri !~ "/$"){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite /(.*) /$1.php last;
}


now I get a Primary script unknown error:
32102#0: *93652 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

http://serverfault.com/questions/517190/nginx-1-fastcgi-sent-in-stderr-primary-script-unknown
that site says:
The error message “primary script unknown” is always related to a wrongly set SCRIPT_FILENAME in the nginx fastcgi_param directive.

I've put in so many hours trying to learn, figure out, get my sites running on nginx... i'm almost out of gas.
I'm struggling to get bits and pieces... trying to get this working

it also mentions, you can test to see if you have the right info -->
Add to http block of main /usr/local/etc/nginx/nginx.conf:
log_format scripts '$document_root$fastcgi_script_name > $request';

thoughts on the above?

thanks
 
okay... ready for the solution?
:)


1) the automatic config, was not correct (or good enough?)... so had to do a global override. My support team redid this:

location ~ ^/~(.+?)(/.*?\.php)(/.*)?$ {
alias /var/www/vhosts/domain.com/web_users/$1/$2;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass "unix:///var/www/vhosts/system/domain.com/php-fpm.sock";
include /etc/nginx/fastcgi.conf; }

and said:
location blocks used regex matching, so to override that, I used the ^~ operator, which is a non-regex match that will stop regex matches from being processed if the location matches.


2) and the Apache & nginx Settings was changed to this

location ^~ /resort/ {
try_files $uri $uri/ /resort.php;
}

so #1 is way over my head
but #2 makes since to me (at least now it does)


so now my URL of domain.com/resort/param1/param2.php works as expected
PS. I did change the /resort file to include the .php to the file name (resort.php). Support said they never seen it work without it or usually have issues if your try without it.

NOTE: my words of advice: test and watch the error logs. I'm glad I picked up on the minor difference in the error. which led me down the right path to the final solution.

THANKS for your help... you helped me get there :)
 
Back
Top