nginx/HHVM 404,修复了用绝对路径替换 $document_root,但重定向将路径添加到 URL

nginx/HHVM 404,修复了用绝对路径替换 $document_root,但重定向将路径添加到 URL

我遇到了与中描述的相同的问题这个问题$document_root,并且用其绝对路径替换的解决方案一直有效,直到重定向将绝对路径添加到 URL,如下所示:

EXPECTED http://domain/pma/
REALITY  http://domain/var/www/pma/

我正要因为沮丧而拔掉头发。请帮助我不要变成秃头。 (虽然保持头发排列本身很麻烦,但你明白了)

$ less /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/log/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm index.php;
    }

    #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   /usr/share/nginx/html;
    }

    include hhvm.conf;

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

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

    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
}

$ less /etc/nginx/hhvm.conf
location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
}

答案1

root指令是在内部定义的location,这会导致您的问题。

root直接在 级别定义指令server会设置变量的正确值$document_root,该值也将在 hhvm.conf 中可用。

server {
    listen       80;
    server_name  localhost;

    root   /var/www;

    location / {
        index  index.php index.html index.htm;
    }

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

    include hhvm.conf;
}

然后,您的内容无需修改hhvm.conf,尽管您可以也在那里做一些清理工作

相关内容