简体   繁体   English

Nginx proxy_pass与乘客

[英]nginx proxy_pass with passenger

I can't seem to make this nginx config work. 我似乎无法使此Nginx配置正常工作。 I have a rails app, and I need to proxy everything under a path to a Java/Tomcat setup. 我有一个Rails应用程序,我需要代理Java / Tomcat设置路径下的所有内容。 I have another route (which does hit the main rails app) under lockdown and that works, but the proxy_pass doesn't; 我在锁定状态下有另一条路线(确实触碰到了主要应用程序),并且可行,但是proxy_pass无效; it just hits the main app. 它只是击中了主应用程序。

  • It seems that when I remove the lockdown location directive, it works. 看来,当我删除lockdown位置指令时,它可以工作。
  • Reordering the two location directives has no effect. 重新排序两个location指令无效。

The basic config: 基本配置:

server {
  listen 80;

  root /rails/app/public;
  rails_env development;
  passenger_enabled on;

  location /JavaApp {
    proxy_pass http://127.0.0.1:8080/JavaApp/;
  }

  location /lockdown {
    # Have to re-enable passenger
    passenger_enabled on;
    allow 127.0.0.1;
    deny all;
  }
}

What am I doing wrong? 我究竟做错了什么?

I thought I had tried every combination, but I went through a bunch more and found that this worked: 我以为我尝试了每种组合,但经过一番尝试后发现这样做有效:

location ~ \.jsp$

Which boggled my mind because before it whined about not allowing regex in the location with proxy_pass, but I had a path in the proxy pass line... SO! 这让我感到困惑,因为在它发出关于不允许使用proxy_pass的位置进行正则表达式的抱怨之前,但是我在代理通过行中有一条路径……所以!

This does the trick 这可以解决问题

location ~ /JavaApp {
  proxy_pass http://127.0.0.1:8080;
}

Try removing passenger_enabled pn; 尝试删除passenger_enabled pn; from the top level of the server {} block and I think it will start working for you. 从服务器{}块的顶层开始,我认为它将开始为您服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM