質問

The subject of this question is my best guess as to the culprit, but I'm not sure that I believe it. My question, in summary, is: what is going wrong with my Sinatra app?

Here's the setup:

  1. I have post '/attachments/go' do … in one of my routes.
  2. I have the following in one of my views:

    <form action="/attachments/go" enctype="multipart/form-data" method="post">
      <input name="attachments[]" type="file" multiple="multiple">
      <button type="submit">upload</button>
    </form>
    
  3. I have two instances of my application running on different ports.

  4. I have Apache set as a reverse proxy:

    …
    <Proxy balancer://myapp/>
      BalancerMember http://127.0.0.1:3006
      BalancerMember http://127.0.0.1:3007
      ProxySet lbmethod=bybusyness
    </Proxy>
    …
    <VirtualHost *:80>
      ServerName myapp.mycompany.com
      ServerAlias myapp
      DocumentRoot "C:/www/myapp/public"
    
      ProxyPass /css !
      ProxyPass /js !
      ProxyPass /images !
      ProxyPass /attachments !
    
      ProxyPass        / balancer://myapp/
      ProxyPassReverse / balancer://myapp/
    </VirtualHost>
    

Here are the symptoms:

  1. When I load my app directly (thin start -e production -p 5142) everything works as expected. I can post the form and receive the file. This also works in development mode.

  2. When I load my app through the reverse proxy and post the form, I get a 404 response:

    The requested URL /attachments/go was not found on this server.
    

I know it's not much to go on, but: any guesses as to why this is happening and how to fix it?

役に立ちましたか?

解決

As usual, the act of posting the question revealed the answer. I have a literal /attachments folder being served by Apache, skipping the Sinatra proxy. And then I named a route with that same name.

This application and code has been working for literally years, so some change introduced by upgrading Sinatra or Rack must have caused the bug. (Either that, or someone else modified the Apache conf without my knowledge.)

Regardless of the culprit, the fix is easy: rename the route to:

post '/attachlings/attach' do
  …
end

and rewrite the view to match, and everything is fine.

Lesson: don't name routes with prefixes that are skipped by the reverse proxy.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top