nginx 将 .php 作为静态文件提供

nginx 将 .php 作为静态文件提供

好吧,这又是一个完全荒谬的问题,我似乎无法弄清楚。nginx 一直将我的 .php 文件作为静态文件提供。我已经通过 ubuntu 上的存储库安装了 nginx。我已经安装了 php5-fpm(那里没有更改配置),两者都已重新启动。据我所知,我的设置与我的笔记本电脑上的设置完全相同,并且它在那里运行。我甚至将文件权限设置为与笔记本电脑上的完全相同,但仍然无济于事。

这是我的 sites-available/default 文件

server {
    #listen   80 default; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /home/johnny/*****; #replaced for privacy's sake
    index index.html index.htm;

    expires       0;

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

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;
    }

    location /doc {
            root /usr/share;
            autoindex on;
            allow 127.0.0.1;
            deny all;
    }

    location /images {
            root /usr/share;
            autoindex off;
    }


    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            include fastcgi_params;
    }

}

顺便说一句,nginx 可以很好地提供静态文件服务。

这是我的 netstat -lptu 输出,以证明 php5-fpm 确实正在运行

   $ sudo netstat -lptu
   Active Internet connections (only servers)
   Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
   tcp        0      0 localhost:ipp           *:*                     LISTEN      1246/cupsd
   tcp        0      0 *:17500                 *:*                     LISTEN      1788/dropbox
   tcp        0      0 localhost:9000          *:*                     LISTEN      10812/main.conf)
   tcp        0      0 localhost:mysql         *:*                     LISTEN      924/mysqld
   tcp        0      0 *:www                   *:*                     LISTEN      10362/nginx
   tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN      1246/cupsd
   udp        0      0 *:17500                 *:*                                 1788/dropbox
   udp        0      0 *:mdns                  *:*                                 802/avahi-daemon: r
   udp        0      0 *:36279                 *:*                                 802/avahi-daemon: r
   udp        0      0 *:bootpc                *:*                                 1275/dhclient
   udp6       0      0 [::]:53816              [::]:*                              802/avahi-daemon: r
   udp6       0      0 [::]:mdns               [::]:*                              802/avahi-daemon: r

fastcgi_params

    fastcgi_param   QUERY_STRING            $query_string;
    fastcgi_param   REQUEST_METHOD          $request_method;
    fastcgi_param   CONTENT_TYPE            $content_type;
    fastcgi_param   CONTENT_LENGTH          $content_length;

    fastcgi_param   SCRIPT_FILENAME         $document_root$fastcgi_script_name;
    fastcgi_param   SCRIPT_NAME             $fastcgi_script_name;
    fastcgi_param   REQUEST_URI             $request_uri;
    fastcgi_param   DOCUMENT_URI            $document_uri;
    fastcgi_param   DOCUMENT_ROOT           $document_root;
    fastcgi_param   SERVER_PROTOCOL         $server_protocol;

    fastcgi_param   GATEWAY_INTERFACE       CGI/1.1;
    fastcgi_param   SERVER_SOFTWARE         nginx/$nginx_version;

    fastcgi_param   REMOTE_ADDR             $remote_addr;
    fastcgi_param   REMOTE_PORT             $remote_port;
    fastcgi_param   SERVER_ADDR             $server_addr;
    fastcgi_param   SERVER_PORT             $server_port;
    fastcgi_param   SERVER_NAME             $server_name;

    # PHP only, required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param   REDIRECT_STATUS         200;
    ~                                                                                                                                                            
    ~                                                         

答案1

尝试注释掉该try_files指令。是否定义了其他虚拟主机,这些虚拟主机可能会覆盖该虚拟主机?

相关内容