PHP,Nginx:当url是sitename.com/ {name}时,调用{name} .php

时间:2016-09-11 08:56:58

标签: php nginx

使用nginx服务器。

当网址为sitename.com/test并且有对test.php的调用

时应该做什么以及如何做

例如:

项目结构

public_html
|
+-somedir1
| |
| +-somefiles....
+-somdir2
|
+-login.php
+-info.php
+-something.php
......

当网址为sitename.com/login时...致电login.phpsitename.com/info致电info.php等。

server {
    listen 80 default;
    root /home/prod/frontend;
    index index.php index.html index.htm;
    charset utf-8;
    server_name ui;
    access_log /var/log/nginx/ui.access.log;
    error_log /var/log/nginx/ui.error.log;
    location / {
        try_files $uri $uri/ /index.php?$args;
    }
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php7.0-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }
    location ~ /\. {
        deny all;
    }
}

我也试试

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

        location / {
            index $uri.php
        }

0 个答案:

没有答案