nginx不会在http:// local -host root中执行index.php文件,而只是下载index.ph



nginx不会在 http://localhost root中执行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

感谢您的帮助。

首先, root指令内部位置是完全有效的,但是在很少情况下,当适合的情况下,这绝对不是这种情况。阅读常见的陷阱。

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

第三,nginx不会执行任何操作。在这种情况下

另外,错误日志中还有很多有用的消息。尝试研究它。

最新更新