Nginx 反向代理时的快速错误
我正在尝试使用Nginx为有内容的CDN设置缓存反向代理 我的配置如下:Nginx 反向代理时的快速错误,nginx,centos,reverse-proxy,contentful,Nginx,Centos,Reverse Proxy,Contentful,我正在尝试使用Nginx为有内容的CDN设置缓存反向代理 我的配置如下: http { proxy_cache_path /my/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$st
http {
proxy_cache_path /my/cache levels=1:2 keys_zone=STATIC:10m inactive=24h max_size=1g;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Load modular configuration files from the /etc/nginx/conf.d directory.
# See http://nginx.org/en/docs/ngx_core_module.html#include
# for more information.
include /etc/nginx/conf.d/*.conf;
server {
listen 443 ssl;
server_name my.domain.com;
server_tokens off;
root /my/www/client;
index index.html;
try_files $uri $uri/ /index.html;
auth_basic "Private Property";
auth_basic_user_file /pass/.htpasswd;
ssl_certificate /my/ssl/cert.crt;
ssl_certificate_key /my/ssl/key.key;
ssl_dhparam /etc/ssl/certs/LS-dhparam.pem;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;
ssl_ciphers 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECD$
location /spaces {
index index.html index.htm;
charset utf-8;
proxy_pass http://cdn.contentful.com/spaces/spaceId/entries?access_token=accessTokenValue;
proxy_ignore_headers Cache-Control Expires;
proxy_cache STATIC;
proxy_cache_valid 200 10m;
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_For;
proxy_set_header Connection "";
proxy_http_version 1.1;
proxy_connect_timeout 90s;
proxy_send_timeout 90s;
proxy_read_timeout 90s;
proxy_buffer_size 4k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
send_timeout 90s;
}
}
}
其中spaceId和accessTokenValue当然是合适的
然后我触发一个请求
返回以下错误:Fastly错误:未知域:my.domain.com。请检查此域是否已添加到服务
当我尝试使用完整url时,它会起作用:
我的nginx配置是否有问题,或者contentful是否有问题?您需要删除
proxy_set_header Host $host;
为了让它发挥作用。因为当您将代理传递到
代理传递时http://cdn.contentful.com/spaces/spaceId/entries?access_token=accessTokenValue&$query_string
,您希望主机名保持为cdn.contentful.com
且不更改它是否希望将参数从原始请求传递到代理传递?url也是绝对的https://my.domain.com/spaces/
否则之后您将有其他内容?我想将参数传递给yes。(您可以在示例中看到这两个URL。我希望将第一个URL转换为第二个URL)然后将proxy\u pass更改为proxy\u passhttp://cdn.contentful.com/spaces/spaceId/entries?access_token=accessTokenValue&$query_string
;看看是否有帮助,我得到了一个502,日志中说我的cdn.contentful.com无法解析,所以我添加了解析器8.8.8.8;回到上面的Fastly错误,我正在写一篇关于调试proxy_pass的文章,很快将与大家分享,这样你就可以发布更多的调试日志了