I have a Java backend app running on Bluemix, and it is working fine. If I go to the backend server address:
http://backend.mybluemix.net/api/test
I get the expected response. Now, I have a front-end application, deploying via the static buildpack, that works for serving the static assets, but I can't seem to get it to proxy to the back-end server correctly.
Here is my full 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;
}
}
}
I've tried various combinations of URIs for the location and proxy_pass. Here is the logging for the nginx install:
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"
That last one looks real promising - got a 200, but I still get an error when I go to:
http://frontend.mybluemix.net/api/test/
And the error is this:
502 Bad Gateway
Edit 1 I have noticed that in some configurations, the request makes it through to the backend server, but the URI has a trailing slash appended, which throws off the server.
http://frontend.mybluemix.net/api/test
Becomes
http://frontend.mybluemix.net/api/test/