【问题标题】:Nginx proxy pass to Rails APINginx 代理传递给 Rails API
【发布时间】:2017-12-29 19:14:25
【问题描述】:

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

我想要对 api 的所有请求,例如:http://127.0.0.1/api/getTranslationLanguages go to API server (Puma) 在 unix 套接字中侦听。

还有我的 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

【问题讨论】:

    标签: nginx proxy


    【解决方案1】:

    它只适用于:

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

    【讨论】:

    • 将增强我的答案,格式在 cmets 中被破坏
    猜你喜欢
    • 2023-03-24
    • 2014-04-06
    • 1970-01-01
    • 2019-01-27
    • 1970-01-01
    • 2019-03-10
    • 2021-09-09
    • 1970-01-01
    • 2012-05-09
    相关资源
    最近更新 更多