C
C
corpsepk2014-08-08 10:29:50
PHP
corpsepk, 2014-08-08 10:29:50

Why does Nginx give the original php code to index.php but execute the rest of the php files?

I configured the server using Vagrant and PUPHPET.
I copied the vhost settings from the combat server (deleting locations that are not important for this problem).
When you go to:
site.dev
site.dev/index.php
nginx gives you the source code of the index.php file.
In this case, if you go, for example, to site.dev/page_doesnt_exist, then index.php is executed.
nginx config

user www-data;
worker_processes 1;
worker_rlimit_nofile 1024;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
  worker_connections 1024;
}

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

  access_log  /var/log/nginx/access.log;

  sendfile    on;

  server_tokens on;

  types_hash_max_size 1024;
  types_hash_bucket_size 512;

  server_names_hash_bucket_size 64;
  server_names_hash_max_size 512;

  keepalive_timeout  65;
  tcp_nodelay        on;

  gzip         on;
  gzip_disable "MSIE [1-6]\.(?!.*SV1)";

  include /etc/nginx/conf.d/*.conf;
  #include /etc/nginx/sites-enabled/*;

  server {
    listen                192.168.56.101:80;

    server_name           site.dev;
    set $yii_bootstrap    "index.php";

    root                  /var/www/site.ru;

    access_log            /var/log/nginx/site.dev.access.log;
    error_log             /var/log/nginx/site.dev.error.log;

    charset utf-8;

    index index.php index.html;

    location / {
        try_files $uri $uri/ /$yii_bootstrap?$args;
    }

    location ~ \.php {
        fastcgi_split_path_info  ^(.+\.php)(.*)$;

        set $fsn /$yii_bootstrap;
        if (-f $document_root$fastcgi_script_name){
            set $fsn $fastcgi_script_name;
        }

        fastcgi_pass   127.0.0.1:9000;
        
        fastcgi_param  SCRIPT_FILENAME  $document_root$fsn;
        fastcgi_param  PATH_INFO        $fastcgi_path_info;
        fastcgi_param  PATH_TRANSLATED  $document_root$fsn;

        include fastcgi_params;
    }

    sendfile off;
  }
}

And it’s strange, if deny all is put down in all locations , then site.dev/index.php and site.dev still give the source code, but site.dev/page_doesnt_exist doesn’t let it in here anymore. But how so? It turns out that the request is being processed by some other location , but I deliberately merged everything into one config so that nothing extra is accidentally picked up ... p.s. If you create a phpinfo.php file and go to site.dev/phpinfo.php , then it is also executed. upd: Added index index.php; :

<? phpinfo();?>

location / {
    index index.php;
    try_files $uri $uri/ /$yii_bootstrap?$args;
}

The site at http://site.dev began to open, but site.dev/index.php still gives the source code.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
T
Taras Serevann, 2014-10-26
@Taras_Serevann

1. Perhaps there is a line in .htaccess that is responsible for this behavior of index.php?
2. Perhaps you have a typo and the file format does not match .php?
3. Perhaps, point 1 is only in configs at the server level?

S
Stanislav Chernov, 2014-11-20
@uinx

And "fastcgi_index" nginx.org/ru/docs/http/ngx_http_fastcgi_module.htm...
location ~ \.php$ {
.....
fastcgi_index index.php;
.....
}

D
drgra, 2015-10-30
@drgra

>> 2. Perhaps you have a typo and the file format does not match .php?
this can be explained.
I once had the same thing. It turned out that the php file
started with <?instead of the prescribed ones . It can also be treated in the php config with the short_open_tag directive <?php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question