node.js - NGINX reverse proxy to docker container running web app -


on host have docker container on port 4012, , in docker container webapp runs on port 3000 ( 0.0.0.0:4012->3000/tcp ) access webapp go http://hostname:4012 , webpage shows fine. want able go http://hostname/metrics run same webpage browser.

while got work adding location nginx.conf on host:
location /metrics {
proxy_pass http://localhost:4012;
}

all loads index.html (i see same html source code @ http://localhost:4012 , http://hostname/metrics) http://hostname/metrics not load javascript assets needed run webapp. developer tools see non proxied site loads assets so: http://hostname:4012/assets/styles.css while proxied version goes /metrics tries load this: http://hostname/assets/styles.css

it doesn't append /metrics assets index.html... missing here? if means anything, webapp running on nodejs express server listening port 3000 on docker container.

you need make app work way

location /metrics/ {     proxy_pass http://localhost:4012/;     sub_filter_once off;     sub_filter 'http://localhost:4012/' '$scheme://$host/metrics/';     sub_filter '<head>' '<head>\n<base href="hostname:4012">'; } 

so adding <base> tag html helps change /css /metrics/css. absolute urls changed using sub_filter.


Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -