Anvil app server behind nginx reverse proxy

Hello,

I would like to use a nginx proxy in front of my anvil-app server (local server deployment). The nginx server is running with a https certificate and the anvil-app-server is running with http. I tried the following nginx settings:

location /SUBPATH {
  #rewrite /SUBPATH/(.*) $1 break;
  proxy_buffering off;
  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 X-NginX-Proxy true;
  proxy_read_timeout 5s;
  proxy_connect_timeout 5s;
  proxy_pass http://ANVILSERVER:3030/;
  proxy_redirect http://ANVILSERVER:3030/ https://MYSERVER/SUBPATH;

  location ~* .+\.(ico|jpe?g|gif|css|js|flv|png|swf)$ {
    proxy_cache backcache;
    proxy_buffering on;
    proxy_cache_min_uses 1;
    proxy_ignore_headers Cache-Control;
    proxy_cache_use_stale updating;
    proxy_cache_key "$scheme$request_method$host$request_uri$is_args$args";
    proxy_cache_valid 200 302 60m;
    proxy_cache_valid 404 1m;
#
    proxy_pass http://ANVILSERVER:3030;
    }

  location = /SUBPATH/ws/ {
    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 X-Forwarded-Proto $scheme;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection “Upgrade”;
    proxy_pass https://ANVILSERVER:3030;
    proxy_read_timeout 60;
    proxy_redirect https://ANVILSERVER:3030/ https://MYSERVER/SUBPATH;
    }
  }

But I am not getting everything from the app to the nginx proxy:

I am starting the anvil server with the following command:

anvil-app-server --app app_name --database "jdbc:postgresql://MYDBINSTANCE/MYDB?username=DBUSER&password=PWD" --disable-tls --ip 0.0.0.0 --port 3030  --origin https://MYSERVER/SUBPATH

Thank you for your help!

Hi @jan.weisenstein,

The App Server assumes it has full control of an origin, so if you want it to coexist with other content you’ll want to run it on a separate subdomain (eg app.myserver.com) rather than a subpath (myserver.com/myapp)

I see both proxy and proxy_redirect - seems to me you should have one or the other.

How are your symbolic names ANVILSERVER and MYSERVER defined? I get the feeling you might be on Windows. My stuff is all Linux and the nginx reverse proxy requires the link from name to IP to be made in /etc/hosts

Hello, I am trying the same thing - anvil local app server behind a nginx reverse proxy, with certbot for https - and I am getting the same output in the browser. Meanwhile, browsing on the local machine/ localhost gives the desired result. Has there been any progress in solving this problem?

Has anyone figured this out? I’m running into the same issue.

Thank you.

For anyone else struggling with this in the future. In my anvil-runtime config.yaml I had to add these options (note that the ORDER of these seems to be important!):

disable-tls: true
origin: “https://FQDN
port: 3030
add-hsts-headers: true

In nginx, I had to add:

server {
        server_name FQDN;
        location / {
                proxy_pass       http://127.0.0.1:3030;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto $scheme;
                proxy_set_header X-Forwarded-Host  $host;
                proxy_set_header X-Forwarded-Port  $server_port;
                proxy_set_header Host $host;
                proxy_set_header X-Real-IP $remote_addr;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection “Upgrade”;
                proxy_read_timeout 60;
                proxy_redirect http://127.0.0.1:3030 https://FQDN;
        }

Did anyone succeed to find a solution to run an anvil app in a subpath of a domain used by other applications ?

I’m running into the same problem. I tried the solution suggested in the previous comment but it’s not working.

Thank you !

We haven’t tried using a sub-path. Maybe you could redirect that sub-path to a new sub-domain that the anvil-runtime would live at?

Anyone found a fix for this, also running into this issue needing to put my anvil app on a subpath

Does this mean each anvil app i would want to put behind my reverse proxy needs it’s own separate subdomain?