I have a functioning setup with an nginx server hosting a site currently. I recently discovered caddy while following a guide for setting up a second site and wanted to migrate over to it. I've gotten it working to the point of both sites having their root loading on the appropriate URLs but I can't get the additional locations to work.
the EXISTING nginx sites-available code
root /var/www/mySite/html/wwwroot;
index index.html index.htm index.nginx-debian.html;
server_name mySite.app www.mySite.app;
location / {
try_files $uri $uri/ =404;
}
location /api/ {
proxy_pass https://127.0.0.1:5001;
}
location /hubs/mainHub {
proxy_pass https://127.0.0.1:5001;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_cache off;
proxy_http_version 1.1;
proxy_buffering off;
proxy_read_timeout 100s;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
listen [::]:443 ssl ipv6only=on; # managed by Certbot
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/mySite.app/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/mySite.app/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 = www.mySite.app) {
return 301 https://$host$request_uri;
} # managed by Certbot
if ($host = mySite.app) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
listen [::]:80;
server_name mySite.app www.mySite.app;
return 404; # managed by Certbot
and the code i have so far in the caddyfile
mySecondSite.net {
reverse_proxy localhost:30000
encode zstd gzip
}
mySite.app {
encode gzip
root * /var/www/mySite/html/wwwroot
file_server
route /api {
reverse_proxy localhost:5001
}
route /hubs/mainHub {
reverse_proxy localhost:5001
}
}
mySecondSite.net is simple and seems to be working fine. mySite.app can get to its home page and seems to be picking up all its web files just fine but the calls back to itself via /api and the websocket connection in hubs/mainHub are failing.
I asked around and read the docs but I'm kind of lost. Is "route" not the correct approach for this or am I just missing some config?
mySite.app is a .net app with an angular front end layered into its www dir the angular app talks to "itself" with the /api end to retrieve the data to display. runs off an index.html in the /var/www/mySite/html/wwwroot
If I missed any relevant information let me know. Any help is appreciated!