Showcase geo tags for calls derived from x-forwarded-for header

This commit is contained in:
Cedric Ziel
2020-10-19 11:55:31 +02:00
parent 3d9ce2607b
commit 83ab82407c
3 changed files with 37 additions and 3 deletions

View File

@@ -1,7 +1,16 @@
FROM nginx:1.16
FROM nginx:1.19
EXPOSE 8080
RUN echo "js_path /opt/nginx_js;" > /etc/nginx/conf.d/njs.conf
RUN echo "\njs_import instana_random_geo.js;\n" >> /etc/nginx/conf.d/njs.conf
RUN echo "\njs_set \$fake_ip instana_random_geo;\n" >> /etc/nginx/conf.d/njs.conf
RUN sed -i '1i load_module \"modules/ngx_http_js_module.so\";' /etc/nginx/nginx.conf
RUN sed -i '1i load_module \"modules/ngx_stream_js_module.so\";' /etc/nginx/nginx.conf
RUN apt update -yqq && apt install nginx-module-njs -y
RUN mkdir -p /opt/nginx_js
COPY instana_random_geo.js /opt/nginx_js/instana_random_geo.js
ENV CATALOGUE_HOST=catalogue \
USER_HOST=user \
CART_HOST=cart \
@@ -14,4 +23,3 @@ ENTRYPOINT ["/root/entrypoint.sh"]
COPY default.conf.template /etc/nginx/conf.d/default.conf.template
COPY static /usr/share/nginx/html

View File

@@ -54,26 +54,32 @@ server {
#}
location /api/catalogue/ {
proxy_set_header x-forwarded-for $fake_ip;
proxy_pass http://${CATALOGUE_HOST}:8080/;
}
location /api/user/ {
proxy_set_header x-forwarded-for $fake_ip;
proxy_pass http://${USER_HOST}:8080/;
}
location /api/cart/ {
proxy_set_header x-forwarded-for $fake_ip;
proxy_pass http://${CART_HOST}:8080/;
}
location /api/shipping/ {
proxy_set_header X-Forwarded-For $fake_ip;
proxy_pass http://${SHIPPING_HOST}:8080/;
}
location /api/payment/ {
proxy_set_header x-forwarded-for $fake_ip;
proxy_pass http://${PAYMENT_HOST}:8080/;
}
location /api/ratings/ {
proxy_set_header x-forwarded-for $fake_ip;
proxy_pass http://${RATINGS_HOST}:80/;
}
@@ -82,4 +88,3 @@ server {
access_log off;
}
}

21
web/instana_random_geo.js Normal file
View File

@@ -0,0 +1,21 @@
var items = [
// white house
"156.33.241.5",
// Hollywood
"34.196.93.245",
// Chicago
"98.142.103.241",
// Los Angeles
"192.241.230.151"
];
// we get a random ip address to simulate specific locations of the requester
function get(r) {
if (process.env.NGINX_INJECT_FAKE_IP != '1') {
return false;
}
return items[Math.floor(Math.random() * items.length)];
}
export default get;