小编Mat*_*w A的帖子

仅当 .php 在 URL 中时,Nginx 才下载 PHP 文件

我知道这是一个受欢迎的问题,但我还没有发现任何人有类似的问题。只要 .php 扩展名不在 url 中,我就可以提供 PHP 文件。例如:

如果我去,我会得到localhost我的 index.php 文件。如果我去localhost/index.php我下载文件。这是我的配置:

server {
    listen 80 default_server;
    listen [::]:80 default_server ipv6only=on;

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

    # Make site accessible from http://localhost/
    server_name localhost;

    location / {
        # First attempt to serve request as file, then
        # as directory, then fall back to displaying a 404.
        try_files $uri $uri/ =404;
        # Uncomment to enable naxsi on this location
        # include /etc/nginx/naxsi.rules
    }

    # Only for nginx-naxsi used …
Run Code Online (Sandbox Code Playgroud)

php nginx

8
推荐指数
1
解决办法
1万
查看次数

标签 统计

nginx ×1

php ×1