Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.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
从nginx中的url中删除.php扩展名_Php_Nginx_Rewrite_Fastcgi - Fatal编程技术网

从nginx中的url中删除.php扩展名

从nginx中的url中删除.php扩展名,php,nginx,rewrite,fastcgi,Php,Nginx,Rewrite,Fastcgi,我有一个nginx服务器正在运行,希望从我的文件中删除.php扩展名。我已经尝试了一些方法,但我唯一能做到的就是打破fastcgi过程,下载php文件。服务器在以下配置下运行正常: ## # Virtual Host configuration for example.com ## server { listen 80; listen [::]:80; server_name example.com www.example.com;

我有一个nginx服务器正在运行,希望从我的文件中删除.php扩展名。我已经尝试了一些方法,但我唯一能做到的就是打破fastcgi过程,下载php文件。服务器在以下配置下运行正常:

##
# Virtual Host configuration for example.com
##

server {
        listen 80;
        listen [::]:80;
        server_name example.com www.example.com;
        return 301 https://www.example.com$request_uri;
}



server {
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GC$
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/letsencrypt/dhparams.pem;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

        root /usr/share/nginx/html/example/;
        index index.php;

        server_name example.com www.example.com;

        location / {
                try_files $uri $uri/ =404;
        }

        location /uploads {
                deny all;
        }

        error_page 404 /templates/404.php;

        location ~ \.php$ {
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
                fastcgi_intercept_errors on;
        }

        location ~*  \.(?:ttf|ttc|otf|eot|woff|font.css|jpg|jpeg|png|gif|ico|css|js)$ {
                expires 365d;
                access_log off;
                add_header Cache-Control "public";
        }

        location ~ /\. {
                deny  all;
        }
}
谢谢你的努力和时间

##
# Virtual Host configuration for example.com
##

server {
        listen 80;
        listen [::]:80;
        server_name example.com www.example.com;
        return 301 https://www.example.com$request_uri;
}



server {
        listen 443 ssl;
        listen [::]:443 ssl;

        ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GC$
        ssl_prefer_server_ciphers on;
        ssl_dhparam /etc/letsencrypt/dhparams.pem;

        ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;

        root /usr/share/nginx/html/example/;
        index index.php;

        server_name example.com www.example.com;

        location / {
                try_files $uri $uri/ @extensionless-php; // add @extensionless-php
        }

        location /uploads {
                deny all;
        }

        error_page 404 /templates/404.php;

        location ~ \.php$ {
                try_files $uri =404; // add this
                fastcgi_split_path_info ^(.+\.php)(/.+)$;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                include fastcgi.conf;
                fastcgi_intercept_errors on;
        }

        location @extensionless-php {         // add this block
                rewrite ^(.*)$ $1.php last;
        }


        location ~*  \.(?:ttf|ttc|otf|eot|woff|font.css|jpg|jpeg|png|gif|ico|css|js)$ {
                expires 365d;
                access_log off;
                add_header Cache-Control "public";
        }

        location ~ /\. {
                deny  all;
        }
}
从该站点

可能重复的