Trying to reverse proxy to API URL not working

Posted March 23, 2020 3.6k views
NginxUbuntu 18.04

Hi all,

I’m trying to create a reverse proxy for my API url and it is not working. The API is working if I use curl localhost:8800. It is on port 8800. My reverse proxy config is as follow:

server {
    listen 80;
    listen [::]:80;

    location /api {
        proxy_pass http://localhost:8800;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_set_header Host $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_cache_bypass $http_upgrade;

I just keep getting 404 error with this. Please help. Thanks.

edited by MattIPv4

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

1 answer

Hi there @knpaing,

Your Nginx Server Block looks correct, as far as I can see it is configured so that it would work if you visit your_droplet_ip/api. What happens if you run:

curl your_droplet_ip/api

If you are still getting a 404 error, I could suggest checking your Nginx access and error logs:

  • tail -100 /var/log/nginx/error.log
  • tail -100 /var/log/nginx/access.log

And also making sure that you’ve restarted Nginx so that the reverse proxy rules have been loaded.

Hope that this helps!

Submit an Answer