【问题标题】:nginx server with dynamic index is not executing php具有动态索引的 nginx 服务器未执行 php
【发布时间】:2021-02-07 18:26:30
【问题描述】:

我尝试在同一位置设置我的 php 后端和我的 vue。服务器应根据 X-Requested-With 标头决定是否使用后端或交付 vue。现在vue文件的投递工作正常了,但是php没有执行。

信息:在X-URI的位置$uri/index.php,但它没有运行php

    # Backend
    if ($http_x_requested_with = "XMLHttpRequest") {
        set $INDEX "index.php";
        set $DOCOUMENTROOT "C:/server/web/www/altv_gadget/public";
        set $SERVING "LaminasMVC";
    }
    
    # Vue Frontend
    if ($http_x_requested_with != "XMLHttpRequest") {
        set $INDEX "index.html";
        set $DOCOUMENTROOT "C:/server/web/www/altv_gadget/dist";
        set $SERVING "Vue";
    }

    # Directory Indexes
    index $INDEX;

    # Document Root
    root $DOCOUMENTROOT;

    # Serving Header
    add_header X-Serving $SERVING;

    # Location
    location / {
        try_files $uri $uri/ /index.php$is_args$args /index.html$is_args$args;
    }

    add_header X-URI $uri;
        
    # For PHP files, pass to php_farm
    location ~ \.php$ {
        add_header     X-PHP "1";
        fastcgi_pass   php_farm;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }

我希望有人知道如何解决这个问题。

【问题讨论】:

  • 您的try_files 语句将下载index.php,因为参数不是最后一个。试试:try_files $uri $uri/ /index.php$is_args$args;

标签: php vue.js nginx header fastcgi


【解决方案1】:

我不知道我的问题是什么,但它似乎工作知道。对于我的具体解决方案,我使用try_files $uri $uri/ /$INDEX$is_args$args; 根据我的参数使用我的index.htmlindex.php

【讨论】:

    猜你喜欢
    • 2018-06-24
    • 2020-11-17
    • 1970-01-01
    • 2019-03-07
    • 2015-04-13
    • 2016-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多