1

So I have configured a reverse proxy using nginx 1.18.0. I am able to access my desired website through the reverse proxy already, but some requests are failing (eg. for the favicon), because the location /app3/ is not included into the request url. Which setting is missing from my conf to make this work? Why are some request working, while others are not?

Please note I am not in control of the target application. It is hosted on the same local network as the nginx, but on a different host. I cannot make any changes there.

Screenshot for reference: https://ibb.co/3WVfMH7

server {
    listen 80 default_server;
    listen [::]:80 default_server;

    root /var/www/html;

    server_name myservername;

    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 Accept-Encoding "";
    gzip_static off;
    
location /app3/ {
            proxy_set_header Accept-Encoding "";
            sub_filter 'href="/'  'href="/app3/';
            sub_filter 'src="/'  'src="/app3/';
            sub_filter 'action="/'  'action="/app3/';
            sub_filter_once off;
            proxy_pass http://172.31.1.102/;
    }
}
Jakub
  • 11
  • 3

2 Answers2

0

The URLs in your pages are created by your application. Therefore you need to configure your application so that it generates correct URLs.

Applications often have the root URL configurable for these situations.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
  • I am not in control of the application, so I cannot make any changes there. I simply want to make it accessible via reverse proxy. The sub_filter directive is working well, but not for all requests. I simply don't understand why. – Jakub Aug 18 '22 at 06:44
  • `sub_filter` is an unreliable solution here, because there can be many ways how the URLs are referred in the code. You need to check the HTML of the page and see the resource references in the code which fail to load. Then you need to compare those with your `sub_filter` settings. – Tero Kilkanen Aug 18 '22 at 20:31
  • I understand. Unfortunately I need to configure the reverse proxy for quite a few different hosts in my local network. Is there maybe a better approach for this? One where I don‘t have to make specific configurations for each host? – Jakub Aug 20 '22 at 14:54
  • The only proper solution is the fix the root URLs in applications. – Tero Kilkanen Aug 21 '22 at 06:17
  • So if I don't have any access to the applications that I want to access using a nginx reverse proxy I am simply out of luck? – Jakub Sep 05 '22 at 09:37
  • Yes, you cannot do what you like in that case. – Tero Kilkanen Sep 05 '22 at 17:09
  • Much thanks, I will think of alternative approaches! – Jakub Sep 05 '22 at 19:57
0

You can prevent favicon.ico requests by adding the following line into nginx configuration:

location = /favicon.ico{ access_log off; log_not_found off; }

You can also add the following line to the <head> section of your index.html file:

<link rel="shortcut icon" href="data:,">

Look like app3 doesn't have any favicon.ico.

soup
  • 56
  • 4