用Nginx如何配置运行无扩展名PHP文件或非.PHP扩展名文件
创始人
2024-03-01 10:40:19
0

用Nginx如何配置运行无扩展名PHP文件或非.PHP扩展名文件

使用Apache + PHP 很容易做到运行无扩展名的PHP文件。
在Nginx中能做到吗?是可以的。
只需将nginx.conf文件中的默认

location ~ .php$ {
…..
}

上的正则表达式 更改为:

location ~ (|.php)$ {

}

就可以了。

同理,可以运行非.php扩展名的PHP文件,如 abc.html, abc.asp, abc.net, abc.jsp 等扩展名的PHP文件。

 

上在代码在php-5.2.17与nginx-0.8.54下通过。

 

nginx.conf文件信息

 

 

user  nobody;

worker_processes  1;

 

error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

 

pid        logs/nginx.pid;

 

 

events {

    worker_connections  1024;

}

 

 

http {

    include       mime.types;

    default_type  application/octet-stream;

 

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

    #                  '$status $body_bytes_sent "$http_referer" '

    #                  '"$http_user_agent" "$http_x_forwarded_for"';

 

    #access_log  logs/access.log  main;

 

    server_names_hash_bucket_size 64;

 

    sendfile on;

    tcp_nopush     on;

    keepalive_timeout 60;

    tcp_nodelay on;

    fastcgi_connect_timeout 120;

    fastcgi_send_timeout 120;

    fastcgi_read_timeout 120;

    fastcgi_buffer_size 64k;

    fastcgi_buffers 4 64k;

    fastcgi_busy_buffers_size 128k;

    fastcgi_temp_file_write_size 128k;

 

    gzip  on;

    gzip_min_length  1k;

    gzip_buffers     4 8k;

    gzip_http_version 1.1;

    gzip_comp_level 2;

    gzip_types       text/plain application/x-javascript text/css application/xml;

    gzip_vary on;

    

    autoindex on;

 

    server {

        listen       8000;

        server_name  218.25.100.62;

        charset utf-8;

        location / {

            root   /opt/lzw/webapps;

            index  index.php index.html index.htm;

        }

        error_page   500 502 503 504  /50x.html;

        location = /50x.html {

            root   html;

        }

        location ~ (|.php)$ {

            root           /opt/lzw/webapps;

            fastcgi_pass   127.0.0.1:9000;

            fastcgi_index  index.php;

            fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;

            include        fastcgi_params;

        }

    }

}

相关内容

PHP+vue+eleme...
运行环境:phpstudy/wamp/xammp等 开发语言&#x...
2025-06-01 10:08:04
nginx总结最全面的面试...
什么是Nginx? Nginx是一个 轻量级/高性能...
2025-05-31 07:40:14
laravel 怎么部署到...
要将 Laravel 应用程序部署到 Nginx 上,...
2025-05-30 20:48:35
Linux环境部署vue项...
1、本地打包、上传 # 打包命令不同项目有略微差别,...
2025-05-29 14:03:13
阿里云服务器使用教程:Ce...
目录 1、下载nginx压缩包 2、配置nginx安装所需环境 3...
2025-05-28 13:21:30
CentOS系统PHP版本...
在CentOS系统中更新PHP版本是确保服务器安全性和功能稳定性的...
2025-05-11 07:49:17

热门资讯

AWSECS:访问外部网络时出... 如果您在AWS ECS中部署了应用程序,并且该应用程序需要访问外部网络,但是无法正常访问,可能是因为...
AWSElasticBeans... 在Dockerfile中手动配置nginx反向代理。例如,在Dockerfile中添加以下代码:FR...
银河麒麟V10SP1高级服务器... 银河麒麟高级服务器操作系统简介: 银河麒麟高级服务器操作系统V10是针对企业级关键业务...
北信源内网安全管理卸载 北信源内网安全管理是一款网络安全管理软件,主要用于保护内网安全。在日常使用过程中,卸载该软件是一种常...
AWR报告解读 WORKLOAD REPOSITORY PDB report (PDB snapshots) AW...
AWS管理控制台菜单和权限 要在AWS管理控制台中创建菜单和权限,您可以使用AWS Identity and Access Ma...
​ToDesk 远程工具安装及... 目录 前言 ToDesk 优势 ToDesk 下载安装 ToDesk 功能展示 文件传输 设备链接 ...
群晖外网访问终极解决方法:IP... 写在前面的话 受够了群晖的quickconnet的小水管了,急需一个新的解决方法&#x...
不能访问光猫的的管理页面 光猫是现代家庭宽带网络的重要组成部分,它可以提供高速稳定的网络连接。但是,有时候我们会遇到不能访问光...
Azure构建流程(Power... 这可能是由于配置错误导致的问题。请检查构建流程任务中的“发布构建制品”步骤,确保正确配置了“Arti...