We got nominated! Help us out and vote for GitHub as Best Bootstrapped Startup of 2008. (You can vote once a day.) [ hide ]

public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Add a 'RailsAllowModRewrite' option for users who really want to use 
mod_rewrite.
Hongli Lai (Phusion) (author)
Tue Apr 01 09:47:22 -0700 2008
commit  34a92665baf89896377174327ab9a1efb173cc47
tree    14adde48657cd0fc184ef357ecdde195a9a3c6ca
parent  f4f506d620326193bec8b5242c43370f2a20dbbd
...
264
265
266
 
 
 
 
 
 
 
 
267
268
269
...
663
664
665
 
666
667
668
...
671
672
673
674
675
676
677
678
679
 
 
 
 
 
 
680
681
682
...
685
686
687
 
 
 
 
 
...
264
265
266
267
268
269
270
271
272
273
274
275
276
277
...
671
672
673
674
675
676
677
...
680
681
682
 
 
 
 
 
 
683
684
685
686
687
688
689
690
691
...
694
695
696
697
698
699
700
701
0
@@ -264,6 +264,14 @@ RailsAutoDetect off
0
 </VirtualHost>
0
 -----------------------------
0
 
0
+[[RailsAllowModRewrite]]
0
+RailsAllowModRewrite <on|off>::
0
+ If enabled, Passenger will not override mod_rewrite rules. Please read
0
+ <<conflicting_apache_modules,Conflicting Apache modules>> for details.
0
++
0
+This option may occur in the global server configuration or in a virtual host
0
+configuration block. The default value is 'off'.
0
+
0
 RailsRuby <filename>::
0
   This option allows one to specify the Ruby interpreter to use.
0
 +
0
@@ -663,6 +671,7 @@ other. Passenger will automatically make use of the correct version.
0
 Passenger does not provide X-Sendfile support by itself. Please install
0
 link:http://tn123.ath.cx/mod_xsendfile/[mod_xsendfile] for X-Sendfile support.
0
 
0
+[[conflicting_apache_modules]]
0
 === Conflicting Apache modules ===
0
 
0
 Passenger conflicts with 'mod_rewrite' and 'mod_alias'. Those modules may be
0
@@ -671,12 +680,12 @@ outside virtual hosts that contain a Rails application, but we recommend you
0
 not to use their features inside virtual hosts that contain a Rails
0
 application.
0
 
0
-Passenger will override mod_rewrite rules on Rails hosts. This is because the
0
-default .htaccess, as provided by Ruby on Rails, redirects all requests to
0
-`dispatch.cgi' using mod_rewrite. This is a CGI application which loads the
0
-entire Ruby on Rails framework for every request, and thus is very slow. If we
0
-do not override mod_rewrite, then Ruby on Rails apps will be slow on Passenger
0
-by default -- but we want a good out-of-the-box experience.
0
+By default, Passenger will override mod_rewrite rules on Rails hosts. This is
0
+because the default .htaccess, as provided by Ruby on Rails, redirects all
0
+requests to `dispatch.cgi' using mod_rewrite. This is a CGI application which
0
+loads the entire Ruby on Rails framework for every request, and thus is very
0
+slow. If we do not override mod_rewrite, then Ruby on Rails apps will be slow
0
+on Passenger by default -- but we want a good out-of-the-box experience.
0
 
0
 Furthermore, the primary reason why people use mod_rewrite with Rails
0
 applications, is to accelerate page caching. Passenger supports page caching
0
@@ -685,3 +694,8 @@ out-of-the-box, without mod_rewrite.
0
 It is not fully understood how mod_alias conflicts with Passenger, but we
0
 recommend you not to use it on Rails virtual hosts. mod_alias rules can result
0
 in surprising problems.
0
+
0
+If you really want to use mod_rewrite on Rails virtual hosts, then please set
0
+the <<RailsAllowModRewrite,RailsAllowModRewrite>> configuration option. But
0
+please note that you will have to delete Rails applications' default .htaccess
0
+file, or add rewrite rules to negate its effects.
...
38
39
40
 
41
42
43
...
53
54
55
 
56
57
58
...
130
131
132
 
 
 
 
 
 
 
133
134
135
...
222
223
224
 
 
 
 
 
225
226
227
...
38
39
40
41
42
43
44
...
54
55
56
57
58
59
60
...
132
133
134
135
136
137
138
139
140
141
142
143
144
...
231
232
233
234
235
236
237
238
239
240
241
0
@@ -38,6 +38,7 @@ void *
0
 passenger_config_create_dir(apr_pool_t *p, char *dirspec) {
0
   DirConfig *config = create_dir_config_struct(p);
0
   config->autoDetect = DirConfig::UNSET;
0
+ config->allowModRewrite = DirConfig::UNSET;
0
   return config;
0
 }
0
 
0
@@ -53,6 +54,7 @@ passenger_config_merge_dir(apr_pool_t *p, void *basev, void *addv) {
0
   }
0
   
0
   config->autoDetect = (add->autoDetect == DirConfig::UNSET) ? base->autoDetect : add->autoDetect;
0
+ config->allowModRewrite = (add->allowModRewrite == DirConfig::UNSET) ? base->allowModRewrite : add->allowModRewrite;
0
   return config;
0
 }
0
 
0
@@ -130,6 +132,13 @@ cmd_rails_auto_detect(cmd_parms *cmd, void *pcfg, int arg) {
0
 }
0
 
0
 static const char *
0
+cmd_rails_allow_mod_rewrite(cmd_parms *cmd, void *pcfg, int arg) {
0
+ DirConfig *config = (DirConfig *) pcfg;
0
+ config->allowModRewrite = (arg) ? DirConfig::ENABLED : DirConfig::DISABLED;
0
+ return NULL;
0
+}
0
+
0
+static const char *
0
 cmd_rails_ruby(cmd_parms *cmd, void *pcfg, const char *arg) {
0
   ServerConfig *config = (ServerConfig *) ap_get_module_config(
0
     cmd->server->module_config, &passenger_module);
0
@@ -222,6 +231,11 @@ const command_rec passenger_commands[] = {
0
     NULL,
0
     RSRC_CONF,
0
     "Whether auto-detection of Ruby on Rails applications should be enabled."),
0
+ AP_INIT_FLAG("RailsAllowModRewrite",
0
+ (Take1Func) cmd_rails_allow_mod_rewrite,
0
+ NULL,
0
+ RSRC_CONF,
0
+ "Whether custom mod_rewrite rules should be allowed."),
0
   AP_INIT_TAKE1("RailsRuby",
0
     (Take1Func) cmd_rails_ruby,
0
     NULL,
...
26
27
28
 
 
29
30
 
 
31
32
33
...
26
27
28
29
30
31
 
32
33
34
35
36
0
@@ -26,8 +26,11 @@
0
      * Per-directory configuration information.
0
      */
0
     struct DirConfig {
0
+ enum Threeway { ENABLED, DISABLED, UNSET };
0
+
0
       std::set<std::string> base_uris;
0
- enum { ENABLED, DISABLED, UNSET } autoDetect;
0
+ Threeway autoDetect;
0
+ Threeway allowModRewrite;
0
     };
0
     
0
     /**
...
459
460
461
462
 
 
 
 
 
 
 
 
 
 
 
 
463
464
465
...
555
556
557
558
 
559
560
561
...
459
460
461
 
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
...
566
567
568
 
569
570
571
572
0
@@ -459,7 +459,18 @@ public:
0
        * interferes with Passenger anyway (it delegates requests
0
        * to the CGI script dispatch.cgi).
0
        */
0
- return OK;
0
+ if (config->allowModRewrite == DirConfig::UNSET
0
+ || config->allowModRewrite == DirConfig::DISABLED) {
0
+ /* Of course, we only do that if the config allows us
0
+ * to. Some people have complex mod_rewrite rules that
0
+ * they don't want to abandon. Those people will have to
0
+ * make sure that the Rails app's .htaccess doesn't
0
+ * interfere.
0
+ */
0
+ return OK;
0
+ } else {
0
+ return DECLINED;
0
+ }
0
     } else {
0
       return DECLINED;
0
     }
0
@@ -555,7 +566,7 @@ passenger_register_hooks(apr_pool_t *p) {
0
   ap_hook_post_config(init_module, NULL, NULL, APR_HOOK_MIDDLE);
0
   ap_hook_child_init(init_child, NULL, NULL, APR_HOOK_MIDDLE);
0
   ap_hook_map_to_storage(map_to_storage, NULL, NULL, APR_HOOK_FIRST);
0
- ap_hook_handler(handle_request, NULL, NULL, APR_HOOK_FIRST);
0
+ ap_hook_handler(handle_request, NULL, NULL, APR_HOOK_MIDDLE);
0
 }
0
 
0
 /**

Comments

    No one has commented yet.