# Replace apache with nginx

**URL:** <https://www.ruby-forum.com/t/replace-apache-with-nginx/244570>\
**Category:** NGINX\
**Created:** [May 5, 2016, 10:26am UTC](https://www.ruby-forum.com/t/replace-apache-with-nginx/244570 "2016-05-05T10:26:01Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rafa\_F](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/958977/32.png) [@Rafa\_F](https://www.ruby-forum.com/u/Rafa_F)\
**Post date:** [May 5, 2016, 10:26am UTC](https://www.ruby-forum.com/t/replace-apache-with-nginx/244570/1 "2016-05-05T10:26:01Z")

</div>

Hello there. I want to migrate my website only on nginx. I setup  
everything, but have issue with my htaccess.

Here is the file:

[root@server]# cat .htaccess  
  
RewriteEngine On  
RewriteRule ^audio-(._).html$ %{ENV:BASE}/audio\_redirect\_mask.php  
[L]  
RewriteRule ^s/(._)$ %{ENV:BASE}/audio\_redirect\_source.php?u=$1 [L]  
  
[root@server]#

Somebody to have good idea, how can I replace this htaccess and execute  
rewrite, without mod\_php with apache or php-fpm?

## Here is the source of both PHP files:

[root@server]# cat audio\_redirect\_mask.php

\<?php if (empty($\_GET['j'])) { $url = '/'; } else { $str = str\_replace(array('-', '\_'), array('/', '+'), $\_GET['j']); $url = '/s/' . base64\_encode(openssl\_decrypt($str, 'AES-256-CBC', 'somesecretpassword2222', 0, '1234567891011121000')); } header("location: $url", true, 302); ------------------------------------------------------------------------------------------------------------ [root@server]# cat audio\_redirect\_source.php \<?php if ($\_GET['u']) { header("X-Robots-Tag: noindex", true); header('Location: ' . base64\_decode($\_GET['u']) , true, 302); } else { header("X-Robots-Tag: noindex", true); header("location: /");

---

<div class="post-metadata">

**Author:** ![Christian\_Ivanov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@Christian\_Ivanov](https://www.ruby-forum.com/u/Christian_Ivanov)\
**Post date:** [May 6, 2016, 1:44pm UTC](https://www.ruby-forum.com/t/replace-apache-with-nginx/244570/2 "2016-05-06T13:44:35Z")

</div>

There is plenty of information around here for you to start.  
Instead of coming here for pre-cooked recipes, you should show you at  
least  
tried…

You could read the  
[http://nginx.org/en/docs/http/ngx\_http\_rewrite\_module.html](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html) docs  
[http://nginx.org/en/docs/http/ngx\_http\_rewrite\_module.html#return](http://nginx.org/en/docs/http/ngx_http_rewrite_module.html#return) or  
some  
tutorials from quality sources  
[https://www.nginx.com/blog/creating-nginx-rewrite-rules/](https://www.nginx.com/blog/creating-nginx-rewrite-rules/).

Since I am in a good mood, Apache redirect rule #2 _might_ (note  
emphasis)  
transform into this:  
location ~\* ^/s/(?.\*)$ {  
return 301 /audio\_redirect\_source.php?u=$source;  
}

## ​Why are you providing backend code again?​ It really feels like ‘I do not understand how the whole thing works and/or I have not thought about that stuff at all, please do it for me’.

_B. R._

On Thu, May 5, 2016 at 10:25 AM, Christian Ivanov \<

---

<div class="post-metadata">

**Author:** ![Christian\_Ivanov](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/b9bd4f/32.png) [@Christian\_Ivanov](https://www.ruby-forum.com/u/Christian_Ivanov)\
**Post date:** [May 10, 2016, 11:09pm UTC](https://www.ruby-forum.com/t/replace-apache-with-nginx/244570/3 "2016-05-10T23:09:33Z")

</div>

On Thu, May 05, 2016 at 11:25:18AM +0300, Christian Ivanov wrote:

Hi there,

> Hello there. I want to migrate my website only on nginx. I setup  
> everything, but have issue with my htaccess.

I’m not entirely sure of what specifically you are looking for here.

Perhaps the secure link module  
([Module ngx\_http\_secure\_link\_module](http://nginx.org/en/docs/http/ngx_http_secure_link_module.html)) or  
other similar things can help?

> Somebody to have good idea, how can I replace this htaccess and execute  
> rewrite, without mod\_php with apache or php-fpm?

Can you describe the intended behaviour here? As in, if I request  
/audio-file.html, what response should I get?

Or alternatively: what request should I make, in order to be sent the  
content of the file /usr/local/nginx/html/audio-file.html?

## f

Francis D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
