Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx proxy_pass 404 error, don't understand why

Tags:

nginx

I am trying to pass off all calls to /api to my webservice but I keep getting 404s with the following config. Calls to / return index.html as expected. Does anyone know why?

upstream backend{     server localhost:8080; }   server {      location /api {         proxy_pass http://backend;     }      location / {         root /html/dir;     } } 

More info here

adept@HogWarts:/etc/nginx/sites-available$ curl -i localhost/api/authentication/check/user/email HTTP/1.1 404 Not Found Server: nginx/1.2.1 Date: Mon, 22 Apr 2013 22:49:03 GMT Content-Length: 0 Connection: keep-alive  adept@HogWarts:/etc/nginx/sites-available$ curl -i localhost:8080/authentication/check/user/email HTTP/1.1 200 OK Content-Type: application/json Date: Mon, 22 Apr 2013 22:49:20 GMT Transfer-Encoding: chunked  {"user":["false"],"emailAddress":["false"]} 
like image 646
Roge Avatar asked Apr 22 '13 22:04

Roge


People also ask

What does 404 not found NGINX mean?

Essentially, the “404 error” indicates that your or your visitor's web browser was connected successfully to the website server or the host. However, it was unable to locate the requested resource, such as filename or any specific URL.

What does proxy_pass do in NGINX?

The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.

How do you check if NGINX reverse proxy is working?

To check the status of Nginx, run systemctl status nginx . This command generates some useful information. As this screenshot shows, Nginx is in active (running) status, and the process ID of the Nginx instance is 8539.


2 Answers

Just want to remind others that the slash(backend*/*) after your proxy_pass url is very important!

if the config is

location /api/ {     proxy_pass http://backend; } 

and you visit http://abc.xyz/api/endpoint, you would be directed to http://backend/api/endpoint;

if the config is

location /api/ {     proxy_pass http://backend/; } 

and you visit http://abc.xyz/api/endpoint, you would be directed to http://backend/endpoint.

That's the difference.

For more, refer to: Nginx reverse proxy return 404

like image 39
d0zingcat Avatar answered Sep 18 '22 14:09

d0zingcat


This

location /api {     proxy_pass http://backend; } 

Needs to be this

location /api/ {     proxy_pass http://backend/; } 
like image 152
Roge Avatar answered Sep 20 '22 14:09

Roge