I'm trying to set up a reverse proxy to my api server but getting a 404 error page.
Context: Whilst setting up a react.js application and trying to find a solution to the CORS problem, I've decided to use reverse proxy (proxy pass) with nginx to invoke the api server internally and trick the browser to think the api is on the same domain.
This is my intended setup:
https://example.com points to the website directory
https://example.com/api calls the api url internally listening on http://127.0.0.1:1234 via nginx reverse proxy
I use hestia cp which has nginx in front of apache as a reverse proxy.
Problem If I use lynx to call directly http://127.0.0.1:1234, I get the correct response from my api server. However, when using it via proxy pass on url https://example.com/api, I get a 404 error page.
Nginx config files
This is my nginx.ssl.conf setup for example.com
location /api/ {
proxy_pass http://127.0.0.1:1234;
access_log /var/log/apache2/domains/example.com-api.log custom;
access_log /var/log/apache2/domains/example.com-api.bytes bytes;
}
This is my nginx.conf setup for my api.com domain, listening on 127.0.0.1, port 1234
server {
listen 127.0.0.1:1234;
server_name 127.0.0.1;
location / {
proxy_pass http://10.0.10.55:8080;
location ~* ^.+\.(jpeg|jpg|png|gif|bmp|ico|svg|tif|tiff|css|js|htm|html|ttf|otf|webp|woff|txt|csv|rtf|doc|docx|xls|xlsx|ppt|pptx|odf|odp|ods|odt|pdf|psd|ai|eot|eps|ps|zip|tar|tgz|gz|rar|bz2|7z|aac|m4a|mp3|mp4|ogg|wav|wma|3gp|avi|flv|m4v|mkv|mov|mpeg|mpg|wmv|exe|iso|dmg|swf)$ {
root /home/user/web/api.com/public_html;
access_log /var/log/apache2/domains/api.com.log combined;
access_log /var/log/apache2/domains/api.com.bytes bytes;
expires max;
try_files $uri @fallback;
}
} location /error/ {
alias /home/user/web/api.com/document_errors/;
}
location @fallback {
proxy_pass http://10.0.10.55:8080;
}
location ~ /\.ht {return 404;}
location ~ /\.svn/ {return 404;}
location ~ /\.git/ {return 404;}
location ~ /\.hg/ {return 404;}
location ~ /\.bzr/ {return 404;} }
Can someone help me debug or troubleshoot this? Can't see anything standing out in the logs but probably don't know what to look for. Seems the call via the nginx proxy pass doesnt' reach apache. I have read that lynx calls apache directly, if I skip nginx if I use the 127.0.0.1:1234 url/port combination.
Many thanks in advance