The original post: /r/nginx by /u/Top_Squirrel2052 on 2024-07-10 09:37:00.
Hello everyone!
I am relatively new to NGINX and I am currently setting up a server to host my React Single Page Application. I’ve encountered a problem with the mirroring of requests, specifically around duplications that I can’t seem to resolve.
My goal is to mirror each request to a monitoring service running on another port (8080). This service needs to capture the IP of clients visiting my website. No matter which path / route a client visits, the request should be mirrored ONCE to the service on port 8080.
I’ve set up the NGINX mirror directive to mirror requests to my monitoring service. However, when someone accesses the root path ‘/’, the request is mirrored TWICE instead of once. Accessing other paths / routes mirrors the request correctly only once. This duplication only occurs at the root path. I think it is because of some internal redirection from ‘/’ to ‘/index.html’.
Here is my current NGINX configuration:
server {
listen 80;
root /var/www/html/dist;
index index.html;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log debug;
location / {
mirror /notifier;
try_files $uri $uri/ /index.html;
}
location = /notifier {
internal;
proxy_pass http://localhost:8080/;
}
location ~* \.(css|js|jpg|jpeg|gif|png|ico|svg|woff|woff2|ttf|eot)$ {
try_files $uri =404;
}
}
nginx version: 1.18.0
If you guys need any more information, feel free to ask!