# Running nginx as reverse proxy with Apache, rewrite problem

**URL:** <https://www.ruby-forum.com/t/running-nginx-as-reverse-proxy-with-apache-rewrite-problem/204694>\
**Category:** NGINX\
**Created:** [March 18, 2011, 7:44pm UTC](https://www.ruby-forum.com/t/running-nginx-as-reverse-proxy-with-apache-rewrite-problem/204694 "2011-03-18T19:44:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 18, 2011, 7:44pm UTC](https://www.ruby-forum.com/t/running-nginx-as-reverse-proxy-with-apache-rewrite-problem/204694/1 "2011-03-18T19:44:48Z")

</div>

I’m using a cPanel plugin located here [cpnginx.com](http://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](http://url) [R=302,L]

I’m constantly getting 500 internal server errors when I added this rule  
and the support at [cpnginx.com](http://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:

> **[Running nginx as reverse proxy with Apache, rewrite problem](https://forum.nginx.org/read.php?2,183798,183798#msg-183798)**
>
> 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....

---

<div class="post-metadata">

**Author:** ![shellcrash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecb155/32.png) [@shellcrash](https://www.ruby-forum.com/u/shellcrash)\
**Post date:** [March 18, 2011, 9:32pm UTC](https://www.ruby-forum.com/t/running-nginx-as-reverse-proxy-with-apache-rewrite-problem/204694/2 "2011-03-18T21:32:36Z")

</div>

Try:

Server {  
server\_name [site.com](http://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](http://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:

> **[Re: Running nginx as reverse proxy with Apache, rewrite problem](https://forum.nginx.org/read.php?2,183798,183819#msg-183819)**
>
> 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....

---

<div class="post-metadata">

**Author:** ![shellcrash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecb155/32.png) [@shellcrash](https://www.ruby-forum.com/u/shellcrash)\
**Post date:** [March 19, 2011, 12:44am UTC](https://www.ruby-forum.com/t/running-nginx-as-reverse-proxy-with-apache-rewrite-problem/204694/3 "2011-03-19T00:44:47Z")

</div>

On 18 Mar 2011 20h30 WET, [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Try:
> 
> Server {  
> server\_name [site.com](http://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](http://mobile.site.com) server.

> ) {  
> rewrite ^ http://site.com$request\_uri redirect;  
> This: rewrite ^ http://site.com$request\_uri? redirect;  
> }  
> location /xyz/ {  
> …  
> }  
> }  
> — appa

---

<div class="post-metadata">

**Author:** ![shellcrash](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecb155/32.png) [@shellcrash](https://www.ruby-forum.com/u/shellcrash)\
**Post date:** [March 19, 2011, 1:12pm UTC](https://www.ruby-forum.com/t/running-nginx-as-reverse-proxy-with-apache-rewrite-problem/204694/4 "2011-03-19T13:12:56Z")

</div>

Thanks so much guys. It worked great.

Posted at Nginx Forum:

> **[Re: Running nginx as reverse proxy with Apache, rewrite problem](https://forum.nginx.org/read.php?2,183798,183905#msg-183905)**
>
> 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....
