Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have an AngularJS app running in a Nginx server. I′m trying to proxy the requests to a Rails API running in Puma.

I would like all the requests to the api like: http://127.0.0.1/api/getTranslationLanguages go to API server (Puma) listening in the unix socket.

and my Nginx config:

upstream api.development {
    # Path to Puma SOCK file, as defined previously
    server unix:/tmp/puma.sock fail_timeout=0;
}

server {
    listen       80;
    server_name  localhost;        

    access_log  logs/host.access.log;
    rewrite_log on;

     location / {
        root   /path-to-app;
        index  index.html index.htm;
        try_files $uri $uri/ /index.html =404;
     }      

     location /api {          
       proxy_pass http://api.development;
     } 
...
}

At the moment I′m getting a 404 error in the request. Error log:

Request URL:http://127.0.0.1/api/getTranslationLanguages
Request Method:GET
Status Code:404 Not Found
Remote Address:127.0.0.1:80
Referrer Policy:no-referrer-when-downgrade
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

It just worked with:

location /api {        
           rewrite ^/api(.*) /$1 break;
           proxy_pass http://api.development;
        }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...