Rewrite migration from apache

On 3 Mar 2008, at 17:50, Igor S. wrote:

I will probably create “log_forbidden on|off”.
Ah, OK. I’m definitely still getting 404s. It’s not desperately urgent
for me as the logs are rotated, but that sounds interesting.

Thanks for your help, Igor.

Hi folks,

The following configuration is giving me 405 Not Allowed errors when I
try to POST to any URI.

I’m guessing that it thinks the URLs are static, but I don’t know why.

Example URI is /admin/clips/edit/63 - but I’ve tried posting to / with
the same result.

Nothing is written to the error_log, even on “info” or “notice”,
though the 405 appears in access_log.

I’ve tried it with fastcgi_intercept_errors and recursive_error_pages
both off, with the same result.

Any ideas on how to fix it would be very welcome.
Thanks very much!
Igor

server {
listen 80;
server_name my.web.site;

access_log  /path/to/logs/access.log  main;
error_log  /path/to/logs/error.log    info;

root    /path/to/public;

# enable nginx to serve custom error pages
# on receiving HTTP error codes from back-end
fastcgi_intercept_errors  on;
recursive_error_pages    on;

# show custom error pages
error_page  403    /403.html;
error_page  404    /404.html;
error_page  500    /500.html;

# deny public access to frontend script
location /frontend.php  {
  internal;
}

# deny public access to admin script
location /admin.php  {
  internal;
}

# serve standard files standardly.
# if file not found, fall back to php app using (rewrite if

neceessary) URL
location / {
rewrite ^/$ /financethemes/index;
rewrite ^/speakers/((?!video).+)/?$ /speakers/video/$1;
rewrite ^/financethemes/((?!video|index).+)/?$
/financethemes/video/
$1;
rewrite ^/transcripts/(speaker|theme)/(.+)/?$ /transcripts/view/
$1/$2;

  error_page  404 =  @phpapp;
}

# serve not found urls using /frontend.php script
location @phpapp {
  fastcgi_pass  127.0.0.1:8888;
  fastcgi_param  SCRIPT_FILENAME    $document_root/frontend.php;
  fastcgi_param  QUERY_STRING    CONTROL_PATH=$uri;
  include    conf/fastcgi_params
}

# IP-restrict anything under /admin
location /admin {
  allow  1.2.3.4;
  deny  all;

  rewrite  ^/admin/?$  /admin/clips/all;

  error_page  404 =  @adminapp;
}

# serve admin app using /admin.php;
location @adminapp {
  fastcgi_pass  127.0.0.1:8888;
  fastcgi_param  SCRIPT_FILENAME    $document_root/admin.php;
  fastcgi_param  QUERY_STRING    CONTROL_PATH=$uri;
  include    conf/fastcgi_params;
}

# use the FLV module for flv files
location ~ \.flv$ {
  flv;
}

# deny access to .svn dirs
location ~ /\.svn {
  deny  all;
}

}

On Thu, Mar 06, 2008 at 05:41:21PM +0000, Igor C. wrote:

The following configuration is giving me 405 Not Allowed errors when I
try to POST to any URI.

I’m guessing that it thinks the URLs are static, but I don’t know why.

Try to change

  • error_page 404 = @…;
  • error_page 404 405 = @…;

Thanks very much!
root /path/to/public;

# serve standard files standardly.
  /transcripts/view/ $1/$2;

  error_page  404 =  @phpapp;
}

You do not need these rewrite’s, use location’s.
The configuration is bigger, but it’s much clearer and so it’s
scaleable:
you can easy add new locations without being afraid to break some
rewrite.

However, you may need to use some rewrite’s in these locations if you
need
to rewrite URI to pass into “location ~ .flv$” with changed URI to
match
common root.

 location = / {
  index    index;
   root    /path/to/public/financethemes;
   error_page  404 =  @phpapp;
}

 location / {
   error_page  404 =  @phpapp;
}

 location /speakers/ {
   alias    /path/to/public/speakers/video/;
   error_page  404 =  @phpapp;
}

 location /speakers/video/ {
   error_page  404 =  @phpapp;
}

 location /financethemes/ {
   alias    /path/to/public/financethemes/video/;
   error_page  404 =  @phpapp;
}

 location /financethemes/video/ {
   error_page  404 =  @phpapp;
}

 location /transcripts/theme/ {
   alias    /path/to/public/transcripts/view/theme/;
   error_page  404 =  @phpapp;
}

 location /transcripts/speaker/ {
   alias    /path/to/public/transcripts/view/speaker/;
   error_page  404 =  @phpapp;
}

On Mon, Mar 10, 2008 at 10:05:17AM +0000, Igor C. wrote:

Thanks Igor. I just tried this and it allows it through, but it
appears to the upstream as a GET. It needs to be a POST as it has
multipart/form-data. Any thoughts?

The patch. It will be included in 0.6.27.

Thanks Igor. I just tried this and it allows it through, but it
appears to the upstream as a GET. It needs to be a POST as it has
multipart/form-data. Any thoughts?

cheers
Igor

Ah, OK. I guess that means I can’t use this configuration then, as I
need to have POST working under /admin.
However I need to IP-restrict /admin, so the previous version I was
using is apparently no good either, so it seems I’m stuck.

Thanks for your help though, I wouldn’t have got this far without it.

Do you have a rough idea when 0.6.27 will be?

Will I need to make significant config changes to migrate from 0.5.35?

cheers,
Igor

Hi Igor, I wonder if you might have a chance to look at this?
Do let me know if there’s any further debug output or anything else I
can provide.
Thanks!

Best,
Igor

Hi Igor,

Looking back, it seems I missed the patch you attached to this email!
Sorry about that.

I see you integrated this change in 0.6.27:

*) Change: now a request method is not changed while redirection
to a
named location via an “error_page” directive.

I’ve tried to run a similar site on 0.6.29 with the same PHP framework
and an almost identical nginx vhost config (attached as
nginx.location.conf), using the “location” style you described,
including “error_page 404 405 = @…”. I haven’t converted all the
“rewrites” to “locations” yet, but there’s no “if (! -f
$request_filename” or similar.

I’m getting some strange and intermittent errors, including apparent
upstream timeouts, and seemingly random Bad Request errors on what
should be simple HREF links. I haven’t been able to make a solid set
of steps to reproduce the Bad Request error yet, so the main problem
is as follows:

POST to /admin/posts/add/

2008/03/31 16:10:33 [debug] 32073#0: *10 delete posted event B7E4D0A4
2008/03/31 16:10:33 [debug] 32073#0: *10 http upstream check client,
write event:1, “/admin/posts/add/”
2008/03/31 16:10:33 [debug] 32073#0: *10 http upstream recv(): -1
(11: Resource temporarily unavailable)
2008/03/31 16:10:33 [debug] 32073#0: *10 delete posted event B7E4D10C

At this point, the browser hangs, and other requests for JS files
which the browser apparently sent at the same time (AJAX?) start to
fail too:

2008/03/31 16:10:34 [debug] 32073#0: *13 free: 082B2BD0
2008/03/31 16:10:34 [debug] 32073#0: *13 delete posted event B7E4D070
2008/03/31 16:10:34 [debug] 32073#0: *13 http empty handler
2008/03/31 16:10:34 [debug] 32073#0: *13 delete posted event B7E82070
2008/03/31 16:10:34 [debug] 32073#0: *13 http keepalive handler
2008/03/31 16:10:34 [debug] 32073#0: *13 recv: fd:22 855 of 1024
2008/03/31 16:10:34 [debug] 32073#0: *13 malloc: 082B2BD0:636
2008/03/31 16:10:34 [debug] 32073#0: *13 event timer del: 22: 90424947
2008/03/31 16:10:34 [debug] 32073#0: *13 generic phase: 0

When I hit “stop” on the browser I get this:

2008/03/31 16:10:56 [info] 32073#0: *13 client closed prematurely
connection, so upstream connection is closed too while sending
request to upstream, client: 82.108.140.18, server: server_name,
request: “GET /scripts/admin/uploader.js HTTP/1.1”, upstream:
“fastcgi://192.168.142.2:9400”, host: “server_name”, referrer: “http://server
_name/admin/posts/add/”

The same PHP code works fine using either 0.5.31 or 0.6.29 and the old-
style config (with lots of “if (! -f…”).

At present I don’t really have much idea whether it’s a problem with
the patch, with my config, or some problem with the PHP server or PHP
code which is only appearing under this circumstance, so I’d be very
grateful for any thoughts you have on the matter!

Best wishes,
Igor

===========
Attachments:

nginx.location.conf - doesn’t work, causes problem described.
nginx.if.conf - works with 0.5.35 and 0.6.29.
nginx.debug.log - debug output from when I press the button which
submits the POST until I press the browser “stop” button.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs