gpt4 book ai didi

php - nginx fastcgi_pass 支持变量吗?

转载 作者:行者123 更新时间:2023-12-04 12:01:37 28 4
gpt4 key购买 nike

我想用 dynamic host resolution使用 nginx 和 fastcgi_pass。

fastcgi_pass $wphost:9000;在conf中设置然后nginx显示错误[error] 7#7: *1 wordpress.docker could not be resolved (3: Host not found),
但是当我设置 fastcgi_pass wordpress.docker:9000;它正在工作,除了在 wordpress 重启后 nginx 仍然指向旧 IP 的事实。

server {
listen [::]:80;
include /etc/nginx/ssl/ssl.conf;

server_name app.domain.*;

root /var/www/html;
index index.php index.html index.htm;

resolver 172.17.42.1 valid=60s;
resolver_timeout 3s;

location / {
try_files $uri $uri/ /index.php?q=$uri&$args; ## First attempt to serve request as file, then as directory, then fall back to index.html
}

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

set $wphost wordpress.docker;

# pass the PHP scripts to FastCGI server listening on wordpress.docker
location ~ \.php$ {
client_max_body_size 25M;
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass $wphost:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_NAME $fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}

location ~* \.(jpg|jpeg|gif|png|css|js|ico|xml)$ {
add_header Pragma public;
add_header Cache-Control "public, must-revalidate, proxy-revalidate";
access_log off;
log_not_found off;
expires 168h;
}

# deny access to . files, for security
location ~ /\. {
access_log off;
log_not_found off;
deny all;
}

}

我使用不同的虚拟主机配置 proxy_pass http://$hostname;在这个设置中,一切都按预期工作,并且找到了主机。

在尝试了不同的选项后,我想知道 fastcgi_pass支持变量

最佳答案

如果您通过 upstream,它确实有效作为一个变量,例如:

upstream fastcgi_backend1 {
server php_node1:9000;
}

upstream fastcgi_backend2 {
server php_node2:9000;
}

server {
listen 80;
server_name _;

set $FASTCGI_BACKEND1 fastcgi_backend1;
set $FASTCGI_BACKEND2 fastcgi_backend2;

location ~ ^/site1/index.php$ {
fastcgi_pass $FASTCGI_BACKEND1;
}

location ~ ^/site2/index.php$ {
fastcgi_pass $FASTCGI_BACKEND2;
}
}

关于php - nginx fastcgi_pass 支持变量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30463779/

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