Bluemix で Java バックエンド アプリを実行していますが、問題なく動作しています。バックエンド サーバーのアドレスにアクセスすると、次のようになります。
http://backend.mybluemix.net/api/test
期待どおりの応答が得られます。現在、静的アセットを提供するために機能する静的ビルドパックを介してデプロイするフロントエンド アプリケーションがありますが、バックエンド サーバーに正しくプロキシすることができないようです。
これが私の完全なnginx.confです:
worker_processes 1;
daemon off;
error_log /home/vcap/app/nginx/logs/error.log;
events { worker_connections 1024; }
http {
log_format cloudfoundry '$http_x_forwarded_for - $http_referer - [$time_local]
"$request" $status $body_bytes_sent';
access_log /home/vcap/app/nginx/logs/access.log cloudfoundry;
default_type application/octet-stream;
include mime.types;
sendfile on;
gzip on;
gzip_disable "msie6";
gzip_comp_level 6;
gzip_min_length 1100;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_types text/plain text/css text/js text/xml text/javascript
application/javascript application/x-javascript application/
json application/xml application/xml+rss;
tcp_nopush on;
keepalive_timeout 30;
port_in_redirect off; # Ensure that redirects don't include the internal container
PORT - 63575
server_tokens off;
server {
listen <%= ENV["PORT"] %> ;
server_name localhost;
location / {
root /home/vcap/app/public;
index index.html index.htm Default.htm;
}
location /api/ {
proxy_pass http://backend.mybluemix.net:80;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
}
location と proxy_pass の URI のさまざまな組み合わせを試しました。nginx インストールのログは次のとおりです。
2016-01-12T10:05:13.785-0600[App/0]ERR[qtp1231318312-15]
INFO spark.webserver.MatcherFilter -
The requested route [/api/test/] has not been mapped in Spark
2016-01-12T10:07:21.551-0600[App/0]ERR[qtp1231318312-19]
INFO spark.webserver.MatcherFilter -
The requested route [/api/test/] has not been mapped in Spark
2016-01-12T10:07:24.679-0600[App/0]ERR[qtp1231318312-17]
INFO spark.webserver.MatcherFilter -
The requested route [/api/test/] has not been mapped in Spark
2016-01-12T10:13:14.335-0600[App/0]ERR[qtp1231318312-16]
INFO spark.webserver.MatcherFilter -
The requested route [/api/test/] has not been mapped in Spark
2016-01-12T10:13:14.325-0600[RTR/3]OUTbackend-1.mybluemix.net -
[12/01/2016:16:13:14 +0000] "GET /api/test/ HTTP/1.1" 404 0 48
"-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36
KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
108.168.250.156:36668 x_forwarded_for:"108.214.198.71"
x_forwarded_proto:"http" vcap_request_id:71f1eefe-72fd-43e3-5aaf-45d5b72eede0
response_time:0.005718652 app_id:9cbede6c-69a9-4830-932d-b830f12ddb38
x_global_transaction_id:"4197164295"
2016-01-12T10:18:23.952-0600[RTR/1]OUTbackend-1.mybluemix.net -
[12/01/2016:16:18:23 +0000] "GET /api/test HTTP/1.1" 200 0 7
"-" "Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36"
108.168.250.153:48575 x_forwarded_for:"108.214.198.71"
x_forwarded_proto:"http" vcap_request_id:c8d86b36-b3b9-4391-5e6d-9378ea3f36be
response_time:0.006252107 app_id:9cbede6c-69a9-4830-932d-b830f12ddb38
x_global_transaction_id:"508431471"
その最後のものは本当に有望に見えます-200を取得しましたが、次の場所に行くとまだエラーが発生します:
http://frontend.mybluemix.net/api/test/
エラーは次のとおりです。
502 Bad Gateway
編集 1 一部の構成では、リクエストがバックエンド サーバーに到達することに気付きましたが、URI の末尾にスラッシュが追加されているため、サーバーからスローされます。
http://frontend.mybluemix.net/api/test
なる
http://frontend.mybluemix.net/api/test/