Redirect app configuration

My YunoHost server

Hardware: VPS bought online
YunoHost version: 11.2.3 (stable)
I have access to my server : Through the webadmin
Are you in a special context or did you perform some particular tweaking on your YunoHost instance ? : no

If your request is related to an app, specify its name and version: app 1.0.2~ynh1

Description of my issue

I’ve a web application runs on Yunohost server. It uses port 3000 to serve. It uses postgresql as db and npm/nodejs for gui. On cli with curl http://127.0.0.1:3000 it responds:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="Tedis - Tedavi izleme sistemi">
    <meta name="author" content="Łukasz Holeczek">
    <meta name="keyword" content="Bootstrap,Admin,Template,Open,Source,CSS,SCSS,HTML,RWD,Dashboard,React">
    <title>Tedis - Tedavi izleme sistemi</title>
    <!--
      manifest.json provides metadata used when your web app is added to the
      homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
    -->
    <link rel="manifest" href="/manifest.json">
    <link rel="shortcut icon" href="/favicon.ico">
    <!--
      Notice the use of  in the tags above.
      It will be replaced with the URL of the `public` folder during the build.
      Only files inside the `public` folder can be referenced from the HTML.

      Unlike "/favicon.ico" or "favicon.ico", "/favicon.ico" will
      work correctly both with client-side routing and a non-root public URL.
      Learn how to configure a non-root public URL by running `npm run build`.
    -->
  </head>
  <body>
    <noscript>
      You need to enable JavaScript to run this app.
    </noscript>
    <div id="root"></div>
    <!--
      This HTML file is a template.
      If you open it directly in the browser, you will see an empty page.

      You can add webfonts, meta tags, or analytics to this file.
      The build step will place the bundled scripts into the <body> tag.

      To begin the development, run `npm start` or `yarn start`.
      To create a production bundle, use `npm run build` or `yarn build`.
    -->
  <script src="/static/js/bundle.js"></script><script src="/static/js/vendors~main.chunk.js"></script><script src="/static/js/main.chunk.js"></script></body>
</html>

My redirect.conf is as follow:

redirect.conf 
location / {
  proxy_pass        http://127.0.0.1:3000;
  proxy_redirect    off;
  proxy_set_header  Host $host;
  proxy_set_header  X-Real-IP $remote_addr;
  proxy_set_header  X-Forwarded-Proto $scheme;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header  X-Forwarded-Host $server_name;
  proxy_set_header  X-Forwarded-Port $server_port;
  
  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";

  # Include SSOWAT user panel.
  include conf.d/yunohost_panel.conf.inc;
  more_clear_input_headers 'Accept-Encoding';

I’ve build a subdomain for it like “sub.domain.com”. I’ve take ssl certificates for both domain and subdomain. Redirect app is convert this oncoming request (sub.domain.com) to Yunohost server’s port 3000 (http://127.0.0.1:3000) as shown on upper.

When I try to connect my app browser says: Invalid Host header.
Let’s encrypt symbol shows as secure connection.

What’s wrong?
Thanks for your attention.

NB: You can also directly include error messages using backticks like this :

nginx/error.log
2023/08/22 13:05:19 [crit] 21771#21771: *709 SSL_do_handshake() failed (SSL: error:141CF06C:SSL routines:tls_parse_ctos_key_share:bad key share) while SSL handshaking, client: 64.227.147.21, server: 0.0.0.0:443
2023/08/22 13:12:59 [info] 22472#22472: Using 131072KiB of shared memory for nchan in /etc/nginx/nginx.conf:61
2023/08/22 13:13:05 [info] 22512#22512: Using 131072KiB of shared memory for nchan in /etc/nginx/nginx.conf:61

domain-access.log
151.135.157.124 - - [22/Aug/2023:13:13:00 +0300] "GET /yunohost/api/services?locale=tr HTTP/2.0" 200 3521 "https://domain.com/yunohost/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"
151.135.157.124 - - [22/Aug/2023:13:13:06 +0300] "GET /yunohost/api/services/nginx?locale=tr HTTP/2.0" 200 218 "https://domain.com/yunohost/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36"

sub.domain-access.log
64.227.147.21 - - [22/Aug/2023:13:05:12 +0300] "GET / HTTP/1.1" 301 162 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
64.227.147.21 - - [22/Aug/2023:13:05:13 +0300] "GET / HTTP/1.1" 200 34 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"

Try proxy_redirect on

Aug 23 11:16:01 domain.com nginx[37426]: nginx: [emerg] invalid parameter “on” in /etc/nginx/conf.d/sub.domain.com.d/redirect.conf:3
Aug 23 11:16:01 domain.com nginx[37426]: nginx: configuration file /etc/nginx/nginx.conf test failed
Aug 23 11:16:01 domain.com systemd[1]: nginx.service: Control process exited, code=exited, status=1/FAILURE

nginx service stopped.

I found a suggetion from:

The problem is that you have caused the Host header to be included twice.

        proxy_set_header Host $host;
        include proxy_params;
Looking at the proxy_params file will show you that it was already set there. Setting it again causes the two values to be joined with a comma.

Inside that file you will find preset headers that will be used when you include that file. You do not need to repeat any of those lines in your own configuration.

ubuntu@vmtest-ubuntu2004:~$ cat /etc/nginx/proxy_params
proxy_set_header Host $http_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 $scheme;
You can remove your own additional proxy_set_header Host $host; from the configuration.

and it works.

My new conf is as follow:

location / {
  proxy_pass        http://127.0.0.1:3000;
  proxy_redirect    off;
#  proxy_set_header  Host $host;
  proxy_set_header  X-Real-IP $remote_addr;
  proxy_set_header  X-Forwarded-Proto $scheme;
  proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header  X-Forwarded-Host $server_name;
  proxy_set_header  X-Forwarded-Port $server_port;

  proxy_http_version 1.1;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";

  # Include SSOWAT user panel.
  include conf.d/yunohost_panel.conf.inc;
  more_clear_input_headers 'Accept-Encoding';
}

Thanks for you attention.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.