我有一个非常奇怪的问题。我的服务器通过proxypass连接到我的api。
server {
listen 80;
server_name www.example.com;
location / {
root /data/sites/www.example.com/public_html/;
index index.php index.html index.htm;
try_files $uri $uri/ /index.php?rt=$uri&$args;
}
location /api {
proxy_pass_header Set-Cookie;
proxy_pass_header P3P;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Fowarded-Host $host;
proxy_set_header X-Real-IP $remote_addr;
port_in_redirect off;
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_pass https://api.example.com/;
proxy_connect_timeout 60;
}
location ~ \.php$ {
root /data/sites/www.example.com/public_html/;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param ENV production;
fastcgi_param HTTPS off;
fastcgi_read_timeout 300;
}
}
因此,网址www.example.com/api是api.example.com的代理传递。但连接总是超时。现在如果我直接在我的浏览器中访问api.example.com,它就可以了!
所以我感到困惑。任何人都有什么想法可以发生什么?
答案 0 :(得分:0)
如果api.example.com
是DNS名称而不是upstream
标签,则可能需要添加解析程序语句以授予nginx
DNS访问权限。
resolver 8.8.8.8;
proxy_pass https://api.example.com/;
有关详细信息,请参阅this document。