由于某种原因,我不得不通过自定义 Lua 解析器为ExpressJSFastCGI路由我的页面……并且它适用于FastCGIExpressJS上的几乎每个页面,但是传递查询参数时PHP 解释器会失败并且由于某种原因将 PHP 显示为 HTML(我尝试了phpinfophpmyadmin,除了查询参数之外,两者都有效,例如phpmyadminhttps://localhost/phpmyadmin/index.php?route=/database/structure&db=brownturbo

例如:

phpyadmin(
):

路线/fastcgi.conf

location ~ /@FastCGI((/[a-zA-Z0-9\-\_\.]+(/+)?)+)? {
    internal;
    # some rate limiting and WAF...
    # and some kind of blocking curl and wget etc...
    if_modified_since off;
    rewrite ^/@FastCGI/(.*)$ /$1 permanent;
    root /var/www/htdocs;
    try_files $uri $request_uri =404;
    fastcgi_pass 127.0.0.1:25680;
    fastcgi_index index.php;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_param DOCUMENT_ROOT $document_root;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param SCRIPT_NAME $fastcgi_script_name;
    fastcgi_param SERVER_PORT $balancer_port;
    #fastcgi_param HTTP_VERSION 2.0;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param PATH_TRANSLATED $document_root$fastcgi_script_name;
    fastcgi_param QUERY_STRING $query_string;
    #fastcgi_param  SERVER_SOFTWARE "lazarus/0.0.1";
    fastcgi_param REQUEST_URI $request_uri;
    fastcgi_param DOCUMENT_URI $document_uri;
    fastcgi_param SERVER_PROTOCOL $server_protocol;
    fastcgi_param COUNTRY_CODE $geoip2_data_country_code;
    fastcgi_param COUNTRY_NAME $geoip2_data_country_name;
    fastcgi_param CITY_NAME $geoip2_data_city_name;
    fastcgi_buffers 8 30k;
    fastcgi_buffer_size 50k;
    fastcgi_hide_header X-Powered-By;
    fastcgi_hide_header X-Page-Speed;
    fastcgi_hide_header X-Application-Version;
    fastcgi_hide_header X-Varnish;
    fastcgi_hide_header Last-Modified;
    fastcgi_hide_header Cache-Control;
    fastcgi_hide_header Vary;
    fastcgi_hide_header X-CF-Powered-By;
    #fastcgi_hide_header  X-FastCGI-Cache;
    fastcgi_cache $FastCGICache;
    fastcgi_cache_key "$scheme:$request_method~$host/$request_uri";
    fastcgi_cache_valid any 10m;
    fastcgi_cache_valid 401 5s;
    fastcgi_cache_valid 403 5s;
    fastcgi_cache_valid 404 5s;
    fastcgi_cache_valid 500 5s;
    fastcgi_cache_valid 501 5s;
    fastcgi_cache_valid 502 5s;
    fastcgi_catch_stderr "PHP Fatal error";
    fastcgi_cache_bypass 0;
    fastcgi_intercept_errors on;
    fastcgi_ignore_client_abort off;
    fastcgi_temp_file_write_size 64k;
    fastcgi_temp_path /var/nginx/fastcgi_temp;
    fastcgi_busy_buffers_size 64k;
    fastcgi_connect_timeout 90s;
    fastcgi_send_timeout 30s;
    fastcgi_read_timeout 60s;
    #fastcgi_send_lowat 12000;
    fastcgi_cache_min_uses 3;
    fastcgi_cache_use_stale error timeout invalid_header http_500 http_503 http_403 http_404;
    fastcgi_cache_methods GET;
    fastcgi_no_cache $skip_cache;
    fastcgi_store off;
    fastcgi_store_access user:rw group:rw all:r;
    include /etc/nginx/fastcgi_params;
    access_log on;
}

lua/routes-resolver.lua

-- some kind of pathname Processing logics
ngx.exec("/@FastCGI", ngx.escape_uri(ngx.var["request_uri"]))
-- some kind of static files serving logics

请注意我尝试过

local _args
if ngx.var["is_args"] == nil or ngx.var["args"] == nil then
    _args = ''
    local _,query = string.match(uri, "([^?]+)%??(.*)")
    if query and #query >= 1 then
        _args = "?" .. query
    end
else
    _args = (ngx.var["is_args"] .. ngx.var["args"])
    if _args:sub(1, 1) ~= "?" then
        _args = "?" .. _args
    end
end
ngx.exec("/@FastCGI", ngx.var["uri"] .. _args)

但这次尝试没有成功,并且
routes/fastcgi.conf

location ~ /@FastCGI(/+)(([a-zA-Z0-9\_\-]+(/)+)+)?([a-zA-Z0-9\-\_]+\.php) {
    # ...
}

lua/routes-resolver.lua

ngx.exec("/@FastCGI" .. ngx.var["uri"], ngx.var["args"])

但这次尝试导致重定向循环

路径/到/fpm/pool.d/www.conf

php_flag[display_errors] = on
php_admin_value[error_log] = "/path/to/fpm/logs/php.www.log"
php_admin_value[disable_functions] = exec,passthru,shell_exec,system
php_admin_flag[log_errors] = On
php_admin_flag[display_errors] = On
php_value[error_reporting] = E_ALL & ~E_DEPRECATED
php_admin_value[memory_limit] = 265M
php_admin_value[max_execution_time] = 60
php_admin_value[max_input_time] = 10
php_admin_value[max_input_vars] = 2500
php_admin_value[post_max_size] = 100M
php_admin_value[upload_max_filesize] = 100M
php_value[default_socket_timeout] = 10
php_value[realpath_cache_size] = 128k
php_value[realpath_cache_ttl] = 86400
php_admin_value[expose_php] = Off
php_admin_value[disable_dir_browsing] = On
php_admin_value[register_globals] = Off
php_value[magic_quotes_gpc] = Off
php_value[safe_mode] = On
php_value[open_basedir] = /var/www/htdocs/tmp:/var/www/htdocs
php_value[session.cookie_httponly] = On
php_value[session.gc_maxlifetime] = 1440
php_admin_value[allow_url_include] = Off
php_admin_value[allow_url_fopen] = Off

我尝试了很多方法来解决这个问题,但没有任何效果……

PHP 版本:8.3.11

NGINX 版本:
1.27.1

phpmyadmin 版本:
5.2.1

2

  • 1
    我不认为这属于“合理的商业惯例”,所以在我看来这与主题无关…但粗略一看,我会说这个正则表达式不会匹配任何带有查询参数的 URL:^(.+\.php)(/.+)$;


    – 

  • @GeraldSchneider 它应该匹配()但似乎在 nginx 中不匹配


    – 

0