gpt4 book ai didi

nginx:将单个静态 URL 映射到 PHP 文件

转载 作者:行者123 更新时间:2023-12-04 18:20:39 24 4
gpt4 key购买 nike

我有一个 WordPress 安装启动并运行,没有问题。页面上有一个元素不是 WP 的一部分,而是我们自己的自定义 PHP 脚本。它只是在那里处理表单 POST 请求并以某种方式处理它。

要求我们没有以 .php 结尾的扩展名。我的表单提交给类似的东西:

/places/signup.html

在我的 nginx 配置中,我有这个:
server {
listen 87948; # It's behind a reverse proxy
server_name domain.com www.domain.com;

include /etc/nginx/proxy_params;

index index.php;
root /opt/www/public_html;

location /favicon.ico {
return 404;
}

location / {
try_files $uri $uri/ /index.php?$args;
}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}

location ~ \.php$ {
add_header Access-Control-Allow-Origin "*";
client_body_buffer_size 4096k;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /opt/www/public_html/$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_script_name;
include /etc/nginx/fastcgi_params;
}

# LOOK HERE
location ~ /places/signup.html {
root /opt/www/custom_scripts/;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME /opt/www/custom_scripts/signup-processor.php;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
include fastcgi_params;
}

}

问题是:fastcgi 或 nginx(我不知道哪个)正在获取文字 URL 并在 location 块的 root 指令中查找它。从错误日志:

2013/01/16 15:30:42 [error] 20533#0: *4 FastCGI sent in stderr: "Unable to open primary script: /opt/www/custom_scripts/places/signup.html (No such file or directory)" while reading response header from upstream, client: 66.172.31.153, server: domain.com, request: "POST /places/signup.html HTTP/1.1", upstream: "fastcgi://unix:/tmp/php5-fpm.sock:", host: "www.domain.com"



我想“fastcgi_param SCRIPT_FILENAME/opt/www/custom_scripts/signup-processor.php;”会强制它使用那个特定的脚本吗?我猜不是?

最佳答案

include最后的指令:

    include         fastcgi_params;

可能还有另一个 fastcgi_param带有 SCRIPT_FILENAME 的指令范围 :
    fastcgi_param   SCRIPT_FILENAME  /another/script/file/name;

由于它位于文件末尾,因此它将覆盖您的值。

如果你想从你的 fastcgi_params 文件中保留一些设置,但用特定的来覆盖它们,你应该放置 include开头的指令:
location ~ /places/signup.html {
include fastcgi_params;
root /opt/www/custom_scripts/;
fastcgi_pass unix:/tmp/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME /opt/www/custom_scripts/signup-processor.php;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
}

关于nginx:将单个静态 URL 映射到 PHP 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14370172/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com