Anvil runner/runtime behind nginx and https

So I want to use anvil with https, but I have nginx with a lot of other apps setup on the same server. So the port 443 is used by those. How can I use https behind nginx?

Edit : I was very vauge but here the issue - Screenshot_119

I presume nginx is handling the TLS termination. In the anvil config you will need to specify the origin url using https://e-commerce.dotcodes.xyz, disable anvil TLS handling and explicitly set the port to 3030. In the nginx config you will need to use the proxy directives to pass requests to http://localhost:3030

1 Like

i did that and it the page doesn’t load at all. This is what I get in the console - Screenshot_120

Can you post both your anvil config and your nginx config please?

1 Like

anvil config - non existant i just use this command in a systemd service - /home/dot/.local/bin/anvil-app-server --app /data/e_commerce --origin https://127.0.0.255:3030 --disable-tls

nginx config -
`server {
server_name e-commerce.dotcodes.xyz;

server_name e-commerce.dotcodes.xyz:3030;

location / {
include proxy_params;
proxy_pass http://127.0.0.255:3030;
}
listen 80;
listen 3030;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/e-commerce.dotcodes.xyz/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/e-commerce.dotcodes.xyz/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
if ($host = e-commerce.dotcodes.xyz) {
return 301 https://$host$request_uri;
} # managed by Certbot

server_name e-commerce.dotcodes.xyz;

listen 80;
return 404; # managed by Certbot
}`

1 Like

The origin config tells anvil what domain the app is hosted on and should match the domain in nginx.
That would be --origin https://e-commerce.dotcodes.xyz
You will also need --port 3030
In your nginx config remove the listen 3030 directive as anvil will be listening on that port
I would have proxy_pass http:127.0.0.1:3030/; (note the trailing slash).
You might need additional directives to handle websocket upgrades on the connection, in which case google is your friend.

1 Like

It looks like websocket connection upgrades are not being handled. Try the following mapping and proxy directives in addition to what you already have:-

map $http_upgrade $connection_upgrade {
    default  upgrade;
    ''       close;
}

location / {
    proxy_http_version  1.1;
    proxy_set_header    Host        $host;
    proxy_set_header    Upgrade     $http_upgrade;
    proxy_set_header    Connection  $connection_upgrade;
    proxy_pass          http://127.0.0.1:3030/;
}
2 Likes

chromium -

firefox -

Edit i did check the files are available just without putting the domain twice and without the comma

Okay, time to put your Sherlock Holmes detective hat on. The firefox screenshot shows that the url request coming from the browser is wrong, containing the duplicated domain name.
image
The screenshot above shows that the base href generated by anvil is the culprit. This comes from the origin config setting, so that will be the place to look. Has it been specified twice?

I used this in a systemd service to start the server -
/home/dot/.local/bin/anvil-app-server --app /data/e_commerce --origin https://e-commerce.dotcodes.xyz --port 3030 --disable-tls

give me a few minutes, I’m currently running sudo grep -Rils "e-commerce.dotcodes.xyz,e-commerce.dotcodes.xyz" / to hopefully find any file containing the mistake

Apparently I edited the config to uwu.dotcodes.xyz and re-ran the stuff but it didn’t change the code in the site, it still showed e-commerce.dotcodes.xyz,e-commerce.dotcodes.xyz
I tried after removing the .anvil-data folder and still same results

File this one under weird and wonderful. It turns out that if the nginx host proxy parameter is specified multiple times it results in the duplication. My guess is that the host parameter was already in your include file and then added again from my previous suggestions. Try removing one of them.

The site partially loads but then -

it looks like the js doesn’t get executed or something like that

edit: I’m unimaginably dumb it;s all working! poggers

1 Like