There seems to be quite a bit floating around the internet about problems such as this, but nothing I have found and tried quite pertains to my particular issue.
I had a functional Plumber api working in Nginx on Digital Ocean, alas when I installed php 8.0.2 and upgraded Ubuntu to 22.04 (and overwrote my conf files then reconfigured them!), it ceased to work. I can see that my R pid is listening to port 3000, and myApi-plumber.service is also directed at port 3000, yet when I test http://127.0.0.1:3000 as root user in console it returns a 404 error instead of an expected 405 (I have provided all info below).
I have not altered any settings in my plumber.R file since it was functional, and it still works perfectly on my local machine, which leads me to suspect it's a server configuration.
I would think I've likely done something incorrectly since, but I've spent days on this and cannot conceive of what it might be. I have adhered to consistent trailing slashes, restarted nginx and rebooted the droplet. I have since spun up new droplets and reinstalled everything from scratch too, but nothing seems to be working. My firewall is also configured as it should be.
Here are my settings:
Nginx version 1.18.0
/etc/nginx/sites-available/default
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
index index.php index.html;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location /myApi/ {
proxy_pass http://127.0.0.1:3000/;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
}'
curl -i http://127.0.0.1:3000
(Here I would expect a '405 - Method not allowed' for a POST API with no JSON content being passed to it)
HTTP/1.1 404 Not Found
Date: Fri, 27 Jan 2023 13:11:52 GMT
Access-Control-Allow-Origin: *
Content-Type: application/json
Content-Length: 36
Webpage form POST request
(Here I would expect a JSON object to get passed to the plumber API and run through an R script which compiles a file from server-side files and becomes available as a link on the page.)
function foo(myCallback) {
$.ajax({
type: "POST",
url: "http://XX.XX.XX.XX/myAPI/",
data: myAPIString,
dataType: "json",
success: myCallback,
})
Returns a 404 xhr error in the network tab of the console in the browser.
sudo lsof -i -P -n | grep LISTEN
R 717 root 15u IPv4 XXXXX 0t0 TCP 127.0.0.1:3000
plumber-API.service - Plumber API
Loaded: loaded (/etc/systemd/system/plumber-API.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-01-27 10:40:03 UTC; 2h 45min ago
Main PID: 717 (R)
Tasks: 4 (limit: 1131)
Memory: 210.8M
CGroup: /system.slice/plumber-myTree.service
└─717 /usr/lib/R/bin/exec/R --no-echo --no-restore -e pr~+~<-~+~plumber::pr('/var/plumber/myApi/plumber.R');~+~pr$setDocs(FALSE);~+~~+~pr$run(port=3000)
Jan 27 10:40:03 ShakenPolygamy systemd[1]: Started Plumber API.
Jan 27 10:40:10 ShakenPolygamy Rscript[717]: Loading required package: maps
Jan 27 10:40:13 ShakenPolygamy Rscript[717]: Running plumber API at http://127.0.0.1:3000
Very frustrating indeed. Any help is so much appreciated!