An alternative approach we think is, we can proxy request to backend application like this
I tried to add location /admin like below, but it always make the CF components failed to communicate with cloud controller, any suggestion?
server {
# use chunkin-http
chunkin on;
error_page 411 = @my_411_error;
location @my_411_error {
chunkin_resume;
}
# end of http-chunkin
listen 80;
client_max_body_size 1024M;
server_name _;
server_name_in_redirect off;
#TODO: how to make this internal location totally transparent to outside
location = /vcapuls {
internal;
# We should use rewrite_by_lua to scrub subrequest headers
# as uls doesn't care those headers at all.
# Given there are some exceptions to clear some headers,
# we just leave them as is.
keepalive_requests 200;
# Don't use unix sockets.
#proxy_pass http://unix:/tmp/router.sock:/;
}
location /nginx {
autoindex on;
root /var/www;
expires max;
}
# Make sure there is a /var/www/nginx/404/404.html page
error_page 404 /nginx/404/404.html;
location /admin {
}
location / {
access_log /home/ubuntu/cloudfoundry/.deployments/intalio_devbox/log/nginx/nginx_router_access.log main;
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;
proxy_set_header X-Forwarded-Proto http;
proxy_redirect off;
proxy_connect_timeout 40;
proxy_send_timeout 480;
proxy_read_timeout 480;
set $health_monitor '';
set $app_id 0;
if ($http_user_agent = "HTTP-Monitor/1.1") {
set $health_monitor T;
}
if ($http_host = "") {
set $health_monitor "${health_monitor}T";
}
if ($health_monitor = TT) {
# Trigger a subrequest to sync the latest few stats of the worker to uls,
# if we have multiple workers, there will be still few stats not synced for
# the workers which don't get this monitor request.
access_by_lua '
local uls = require ("uls")
ngx.log(ngx.DEBUG, "monitor trigger stats syncup")
local req = uls.generate_stats_request()
-- generate one subrequest to uls to update stats
ngx.location.capture(
"/vcapuls", { body = req }
)
';
more_set_input_headers "Authorization: Basic YWRtaW46cGFzc3dvcmQ=";
rewrite ^.*$ /healthz break;
}
# We intend to have one "if" block to avoid the above monitor location
# to twist with below upstream locator server handling.
# ("if" block effectively creates a nested location and will inherit
# all the rewrite/access phase handlers of outer location)
if ($health_monitor != TT) {
# The following variables are used by lua module code.
# DO NOT remove or rename any of them!
set $backend_addr ''; # Backend server address returned from uls for this request
set $uls_req_tags ''; # Request tags returned from uls for this request to catalog statistics
set $router_ip '';
set $timestamp 0;
set $trace '';
set $sticky '';
access_by_lua '
local uls = require ("uls")
uls.pre_process_subrequest(ngx, "222")
local req = uls.generate_uls_request(ngx)
-- generate one subrequest to uls for querying
local res = ngx.location.capture(
"/vcapuls", { body = req }
)
uls.post_process_subrequest(ngx, res)
';
proxy_pass http://$backend_addr;
# Handling response from backend servers
header_filter_by_lua '
local uls = require ("uls")
uls.post_process_response(ngx)
';
}
}