Nginx代理传递给Rails API

时间:2017-12-29 19:14:25

标签: nginx proxy

我有一个在Nginx服务器上运行的AngularJS应用程序。我试图将请求代理到在Puma中运行的Rails API。

我想要api的所有请求:http://127.0.0.1/api/getTranslationLanguages转到在unix套接字中监听的API服务器(Puma)。

和我的Nginx配置:

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;
     } 
...
}

目前我在请求中遇到404错误。 错误日志:

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

1 个答案:

答案 0 :(得分:-1)

它只适用于:

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