Question

Trying to reverse proxy to API URL not working

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.

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

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:

  1. tail -100 /var/log/nginx/error.log
  2. 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! Regards, Bobby