Running nginx as reverse proxy with Apache, rewrite problem

I’m using a cPanel plugin located here cpnginx.com that allows me to use
nginx to serve static content and Apache to serve dynamic content. They
use a method called Direct Push so that I’m still able to use my apache
htaccess rules with the setup. Tonight I’ve run into a problem trying
to add a new rule to my .htaccess file to redirect all my mobile
traffic:

RewriteCond %{HTTP_USER_AGENT}
(mobile|android|blackberry|brew|htc|j2me|lg|midp|mot|netfront|nokia|obigo|openweb|opera
mini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|wap|webos|windows
ce) [NC]
RewriteRule ^(.*)$ http://url [R=302,L]

I’m constantly getting 500 internal server errors when I added this rule
and the support at cpnginx.com isn’t able to help me at all. Is there
anyone out there that can provide me with some advice?

Thanks

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183798,183798#msg-183798

Try:

Server {
server_name site.com;
listen 80;
root /path/to/regular/content/;
if ($http_user_agent ~*
(mobile|android|blackberry|brew|htc|j2me|lg|midp|mot|netfront|nokia|obigo|openweb|opera\smini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|wap|webos|windows\sce)
) {
rewrite ^ http://mobile.site.com$request_uri redirect;
}
location /xyz/ {

}
}

Server {
server_name mobile.site.com;
listen 80;
root /path/to/mobile/content/;
if ($http_user_agent !~*
(mobile|android|blackberry|brew|htc|j2me|lg|midp|mot|netfront|nokia|obigo|openweb|opera\smini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|wap|webos|windows\sce)
) {
rewrite ^ http://site.com$request_uri redirect;
}
location /xyz/ {

}
}

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183798,183819#msg-183819

On 18 Mar 2011 20h30 WET, [email protected] wrote:

Try:

Server {
server_name site.com; listen 80; root
/path/to/regular/content/; if ($http_user_agent ~*

(mobile|android|blackberry|brew|htc|j2me|lg|midp|mot|netfront|nokia|obigo|openweb|opera\smini|palm|psp|samsung|sanyo|sch|sonyericsson|symbian|symbos|teleca|up.browser|wap|webos|windows\sce)

) {
rewrite ^ http://mobile.site.com$request_uri redirect;

Remember to add ‘?’ at the end, otherwise you risk repeating the
query arguments.

Should be: rewrite ^ http://mobile.site.com$request_uri? redirect;

Ditto for the mobile.site.com server.

) {
rewrite ^ http://site.com$request_uri redirect;
This: rewrite ^ http://site.com$request_uri? redirect;
}
location /xyz/ {

}
}
— appa

Thanks so much guys. It worked great.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,183798,183905#msg-183905

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