# Server name rewrite

**URL:** <https://www.ruby-forum.com/t/server-name-rewrite/235396>\
**Category:** NGINX\
**Created:** [June 19, 2013, 8:22pm UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396 "2013-06-19T20:22:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [June 19, 2013, 8:22pm UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396/1 "2013-06-19T20:22:55Z")

</div>

Hi, guys!

E.g. I have server new\_server\_name.com and want to rewrite requests to  
www.new\_server\_name.com and old\_server\_name.com to present server.

From [Pitfalls and Common Mistakes | NGINX](http://wiki.nginx.org/Pitfalls) I use two server’s {} directives for  
this instead if().

server {  
server\_name www.new\_server\_name.com old\_server\_name.com;  
return 301 $scheme://new\_server\_name.com$request\_uri;  
}

server {  
listen 10.15.1.2:80;  
server\_name new\_server\_name.com;

… server staff…  
}

But this doesn’t work and first server {} directive MUST have listen  
directive as well.

So, or I am do something wrong or wiki-page doesn’t clear describe this  
situation?

–  
Cheers,  
w

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [June 19, 2013, 9:05pm UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396/2 "2013-06-19T21:05:35Z")

</div>

Is anyone maintaining a “current” version of nginx with mod-security  
linked-in?

I realize this is a bit lazy on my part – the instructions seem  
relatively straightforward to build – but I didn’t want to “re-invent  
the wheel” if I didn’t have to.

Thanks,  
AJ

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [June 19, 2013, 9:24pm UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396/3 "2013-06-19T21:24:52Z")

</div>

I do a custom-build for our own servers (in private pkg-ng repository)  
with a handful of useful modules included. Because the truth is: only  
you know what modules you want or need.

This is absolutely true. (And I’m running CentOS and have been very  
happy as well.)

Thanks.

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [June 19, 2013, 9:13pm UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396/4 "2013-06-19T21:13:11Z")

</div>

Am 19.06.2013 um 21:04 schrieb AJ Weber [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Is anyone maintaining a “current” version of nginx with mod-security linked-in?
> 
> I realize this is a bit lazy on my part – the instructions seem relatively  
> straightforward to build – but I didn’t want to “re-invent the wheel” if I didn’t  
> have to.

The FreeBSD port recently gained support for mod\_security.

> **[FreshPorts -- www/nginx: Robust and small WWW server](https://www.freshports.org/www/nginx/)**
>
> NGINX is a high performance edge web server with the lowest memory footprint
> and the key features to build modern and efficient web infrastructure.
> 
> NGINX functionality includes HTTP server, HTTP and mail reverse proxy, caching,
> load balancing,...

You can even build the dev-version:

> **[FreshPorts -- www/nginx-devel: Robust and small WWW server](https://www.freshports.org/www/nginx-devel/)**
>
> NGINX is a high performance edge web server with the lowest memory footprint
> and the key features to build modern and efficient web infrastructure.
> 
> NGINX functionality includes HTTP server, HTTP and mail reverse proxy, caching,
> load balancing,...

FreeBSD + nginx works super-smooth.

I do a custom-build for our own servers (in private pkg-ng repository)  
with a handful of useful modules included.  
Because the truth is: only you know what modules you want or need.

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [June 19, 2013, 11:28pm UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396/5 "2013-06-19T23:28:08Z")

</div>

On Wed, Jun 19, 2013 at 09:22:11PM +0300, wishmaster wrote:

Hi there,

> From [GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Pitfalls) I use two server’s {} directives for this  
> instead if().

> But this doesn’t work and first server {} directive MUST have listen directive  
> as well.

> **[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html)**

A request comes to an ip:port. nginx chooses the set of best-match  
servers  
for that ip:port. A request indicates which Host: it cares about. nginx  
chooses the one matching server from that set of servers.

Which means (approximately): if you want all possible server{} blocks to  
be available to match a request, they should all have the same “listen”  
directives.

> So, or I am do something wrong or wiki-page doesn’t clear describe this  
> situation?

That wiki page section doesn’t any “listen” directives. I imagine the  
author thought that that aspect was out of scope for that document.

## f

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

---

<div class="post-metadata">

**Author:** ![wishmaster](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f4b2a3/32.png) [@wishmaster](https://www.ruby-forum.com/u/wishmaster)\
**Post date:** [June 20, 2013, 7:02am UTC](https://www.ruby-forum.com/t/server-name-rewrite/235396/6 "2013-06-20T07:02:00Z")

</div>

Thank you Francis, your answer is exhaustive, as always.

— Original message —  
From: “Francis D.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
Date: 20 June 2013, 00:27:48
