Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
187 views
in Technique[技术] by (71.8m points)

Nginx proxy pass to Rails API

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

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

1 Reply

0 votes
by (71.8m points)

It just worked with:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...