Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 可以更改nginx';指数';基于域地址后URL的第一段动态_Php_Nginx - Fatal编程技术网

Php 可以更改nginx';指数';基于域地址后URL的第一段动态

Php 可以更改nginx';指数';基于域地址后URL的第一段动态,php,nginx,Php,Nginx,我已经在nginx文件中设置了根目录:/var/www/html/public 我的域名是example.com 我想实现这一点,如果我键入example.com/first,它将运行/var/www/html/public/first.php文件 如果我键入example.com/second,它将运行/var/www/html/public/second.php 如果我键入example.com/third,它将运行/var/www/html/public/third.php 这甚至是可能的

我已经在nginx文件中设置了根目录:/var/www/html/public

我的域名是example.com

我想实现这一点,如果我键入example.com/first,它将运行/var/www/html/public/first.php文件

如果我键入example.com/second,它将运行/var/www/html/public/second.php

如果我键入example.com/third,它将运行/var/www/html/public/third.php


这甚至是可能的?

@Richard Smith的建议给了我巨大的支持。我搜索无扩展php,因为不是每个人都知道这一点(像我以前一样),所以我粘贴了我的nginx配置,这正是我想要实现的

server {
    listen 80;

    root /vagrant/public;

    # Add index.php to the list if you are using PHP
    index index.php index.html index.htm;

    server_name your_domain_name; #for example example.com

    location / {
         try_files $uri $uri/ @extensionless-php;
         index index.php index.html;
    }
    location @extensionless-php {
         rewrite ^(.*)$ $1.php last;
    }

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    # You must use this, because if You not use it, You will get surce code instead of result of php script execution.
    location ~ \.php(/|$)  {
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

您可以在这里搜索“无扩展php”-有很多解决方案。@RichardSmith谢谢:)