【发布时间】:2015-08-08 10:28:01
【问题描述】:
我想将dynamic host resolution 与 nginx 和 fastcgi_pass 一起使用。
当在conf中设置fastcgi_pass $wphost:9000;时,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 是否支持变量
【问题讨论】:
-
wordpress.host,还是wordpress.docker? -
wordpress.docker 是正确的域名。我相应地更新了我的问题。
-
+1 在这里。我是 AWS 内部 ELB 的 fastcgi_pass,它会随着时间的推移更改 IP 地址。仍在寻找解决方案。
-
也许这有点帮助:ruby-forum.com/topic/173585
-
您好,您找到了如何在 fastcgi_pass 中使用变量的解决方案吗?