nginx不执行http:// localhost root中的index.php文件,只下载index.php文件

时间:2014-03-08 20:13:09

标签: macos nginx localhost virtualhost

nginx不会在http://localhost根目录中执行index.php文件。我还将default_type application/octet-stream;更改为default_type application/html;但没有运气。以下是nginx.conf文件:

user  nobody;
worker_processes  1;
error_log /usr/local/Cellar/nginx/1.4.6/logs/error.log;
pid       /usr/local/Cellar/nginx/1.4.6/logs/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /usr/local/etc/nginx/mime.types;
    include       /usr/local/etc/nginx/fastcgi.conf;
    default_type  application/octet-stream;
    access_log    /usr/local/var/log/nginx/access.log;

    sendfile        on;
    tcp_nopush     on;
    keepalive_timeout  65;
    gzip  on;
    server {
        listen       80;
        server_name  localhost;
        access_log  /usr/local/Cellar/nginx/1.4.6/logs/localhost.access.log  combined;

        location / {
            root   /Users/apiah/Websites/test;
            index  index.html index.htm index.php;
        }
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            include        /usr/local/etc/nginx/fastcgi_params;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

此外,以下是终端中nginx -V命令的信息:

TLS SNI support enabled configure arguments: --prefix=/usr/local/Cellar/nginx/1.4.6 --with-http_ssl_module --with-pcre --with-ipv6 --sbin-path=/usr/local/Cellar/nginx/1.4.6/bin/nginx --with-cc-opt='-I/usr/local/Cellar/pcre/8.34/include -I/usr/local/Cellar/openssl/1.0.1f/include' --with-ld-opt='-L/usr/local/Cellar/pcre/8.34/lib -L/usr/local/Cellar/openssl/1.0.1f/lib' --conf-path=/usr/local/etc/nginx/nginx.conf --pid-path=/usr/local/var/run/nginx.pid --lock-path=/usr/local/var/run/nginx.lock --http-client-body-temp-path=/usr/local/var/run/nginx/client_body_temp --http-proxy-temp-path=/usr/local/var/run/nginx/proxy_temp --http-fastcgi-temp-path=/usr/local/var/run/nginx/fastcgi_temp --http-uwsgi-temp-path=/usr/local/var/run/nginx/uwsgi_temp --http-scgi-temp-path=/usr/local/var/run/nginx/scgi_temp --http-log-path=/usr/local/var/log/nginx/access.log --error-log-path=/usr/local/var/log/nginx/error.log --with-http_gzip_static_module

感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

首先,位置内的root指令是完全有效的,但是在适当的情况下几乎没有这种情况,但绝对不是这种情况。阅读common pitfalls

其次,相对根路径(在您的情况下为root html;)相对于nginx默认路径。你知道这是什么吗?是的,如您帖子中所述/usr/local/Cellar/nginx/1.4.6。所以root html;等效root /usr/local/Cellar/nginx/1.4.6/html;。我想,没有PHP文件。

第三,nginx不执行任何操作。在这种情况下,nginx代理您对端口9000上的fastcgi应用程序的请求(我的客人,它是php-fpm或类似的东西)。

此外,错误日志中有许多有用的消息。试着调查一下。