繁体   English   中英

Nginx将php文件作为“未找到”

[英]Nginx serves php files as 'not found'

我正在尝试配置Nginx服务器以提供php文件。

我已经使用brew安装了php 7.1(带有fpm)。 php -vphpfpm -v给了我很好的版本。

我的nginx配置如下所示:

server {
  listen       80;
  server_name  localhost;

  access_log  /Library/Logs/nginx/access.log  main;

  location / {
      root   /Users/tomek/Sites;
      index  index.html index.htm index.php;
      try_files $uri $uri/ /index.php?$args;
  }

  #error_page  404              /404.html;

  # redirect server error pages to the static page /50x.html
  #
  error_page   500 502 503 504  /50x.html;
  location = /50x.html {
      root   html;
  }

  location ~ \.php$ {
    fastcgi_pass 127.0.0.1:9000;

    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
  }
}

我该怎么办?

问题可能是由于:

fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;

这是我在服务器上使用的一个示例nginx配置文件,它也可以为您正常工作:

server {
    listen 80;
    server_name  _ default_server;

    root /usr/share/nginx/html/;

    # Main Settings
    location / {
        root   /usr/share/nginx/YOUR_PHP_FOLDER;
        index  index.php;

        try_files $uri $uri/ /index.php$is_args$args;

        location ~ \.php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_read_timeout 300; 
        }

        location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
            expires 365d;
            gzip_vary on; 
        }
    }

    # Handle Not Found Page
    error_page  404              /404.html;

    # Handle Server Errors
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # Disable Apache .htaccess
    location ~ /\.ht {
        deny  all;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM