# Nginx configuration issues

**URL:** <https://www.ruby-forum.com/t/nginx-configuration-issues/170455>\
**Category:** NGINX\
**Created:** [June 17, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/nginx-configuration-issues/170455 "2009-06-17T19:28:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joel\_Dahl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Joel\_Dahl](https://www.ruby-forum.com/u/Joel_Dahl)\
**Post date:** [June 17, 2009, 7:28pm UTC](https://www.ruby-forum.com/t/nginx-configuration-issues/170455/1 "2009-06-17T19:28:10Z")

</div>

Hi,

I’ve been looking at replacing apache with nginx for a while and today I  
had  
some time over to play with the nginx configuration. I have around ~40  
websites and my goal is to set up nginx to handle more websites without  
me  
needing to reconfigure anything (I would like to avoid creating a new  
virtual  
host every time a new website needs to be created). This is just a test  
of  
course, and not anywhere near production.

My nginx.conf looks like this (don’t hesitate to suggest improvements,  
this is  
my first nginx.conf file after all):

user www www;

worker\_processes 1;

pid /var/run/nginx.pid;  
error\_log /var/log/nginx\_error.log;

events {  
worker\_connections 1024;  
}

http {  
include mime.types;  
default\_type application/octet-stream;

```
 log_format main '$remote_addr - $remote_user [$time_local] $request 

```

’  
'“$status” $body\_bytes\_sent “$http\_referer” ’  
‘“$http\_user\_agent” “$http\_x\_forwarded\_for”’;

```
 sendfile on;
 tcp_nopush on;
 tcp_nodelay off;
 keepalive_timeout 65;

 server_names_hash_bucket_size 128;

 gzip on;

 server {
     listen 80;
     server_name _;

     location / {
         root /home/w/$host;
         index index.php index.html index.htm;
     }

     error_page 500 502 503 504 /50x.html;
     location = /50x.html {
         root /usr/local/etc/nginx/errorpages;
     }

     error_page 404 /404.html;
     location = /404.html {
         root /usr/local/etc/nginx/errorpages;
     }

     location ~ \.php$ {
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME 

```

/home/w/$host$fastcgi\_script\_name;  
fastcgi\_param QUERY\_STRING $query\_string;  
fastcgi\_param REQUEST\_METHOD $request\_method;  
fastcgi\_param CONTENT\_TYPE $content\_type;  
fastcgi\_param CONTENT\_LENGTH $content\_length;  
fastcgi\_intercept\_errors on;  
}

```
     location ~ /\.ht {
         deny all;
     }
 }

```

}

…and at first it seemed to work. If the directory /home/w/www.foo.com  
exists, requests to [www.foo.com](http://www.foo.com) works and I can see the website.  
However, if  
I try to access [www.foo.com/bar](http://www.foo.com/bar) I get a “can’t find the domain  
[www.foo.com](http://www.foo.com)”  
type of error message in my browser. Browsing to [www.foo.com/bar/](http://www.foo.com/bar/) works  
however, and [www.foo.com/bar/index.php](http://www.foo.com/bar/index.php) also works.

What am I doing wrong? 🙂

---

<div class="post-metadata">

**Author:** ![Joel\_Dahl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Joel\_Dahl](https://www.ruby-forum.com/u/Joel_Dahl)\
**Post date:** [June 17, 2009, 7:38pm UTC](https://www.ruby-forum.com/t/nginx-configuration-issues/170455/2 "2009-06-17T19:38:09Z")

</div>

On Wed, Jun 17, 2009 at 05:44:19PM +0200, Joel Dahl wrote:

> is my first nginx.conf file after all):  
> }  
> tcp\_nopush on;
> 
> ```
> error_page 404 /404.html;
> fastcgi_param CONTENT_TYPE $content_type;
> 
> ```
> 
> …and at first it seemed to work. If the directory /home/w/www.foo.com  
> exists, requests to [www.foo.com](http://www.foo.com) works and I can see the website. However,  
> if I try to access [www.foo.com/bar](http://www.foo.com/bar) I get a “can’t find the domain  
> [www.foo.com](http://www.foo.com)” type of error message in my browser. Browsing to  
> [www.foo.com/bar/](http://www.foo.com/bar/) works however, and [www.foo.com/bar/index.php](http://www.foo.com/bar/index.php) also works.
> 
> What am I doing wrong? 🙂

Add

```
server {
   server_name_in_redirect on;

```

otherwise nginx uses “_" as server name in redirect: "http://_/bar/”.

---

<div class="post-metadata">

**Author:** ![Joel\_Dahl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Joel\_Dahl](https://www.ruby-forum.com/u/Joel_Dahl)\
**Post date:** [June 17, 2009, 8:28pm UTC](https://www.ruby-forum.com/t/nginx-configuration-issues/170455/3 "2009-06-17T20:28:03Z")

</div>

Igor S. skrev:

> ```
> server {
> server_name_in_redirect on;
> 
> ```
> 
> otherwise nginx uses “_" as server name in redirect: "http://_/bar/”.

Ah yes, that helped. Thanks.

However, I found another issue which is somewhat confusing, and I can’t  
figure  
out what I’m doing wrong.

In /home/w/www.foo.com I have a link file to a wiki that resides in  
another  
place in the directory structure. /home/w/www.foo.com/wiki points to →   
/usr/local/www/wiki like this:

root@www [/home/w/www.foo.com] ls -l  
drwxr-xr-x 2 root wheel - 512B Jun 16 22:13 bar/  
-rw-r–r-- 1 root wheel - 20B Jun 16 21:24 index.php  
lrwxr-xr-x 1 root wheel - 23B Jun 16 21:22 wiki@ →   
/usr/local/www/wiki

Accessing [http://www.foo.com/wiki](http://www.foo.com/wiki) in my browser should bring me to the  
front  
page (index.php) on the wiki, and yes it does. It doesn’t load any  
images or  
css-files however.

I checked the logs, and found loads of entries like this one:

2009/06/17 19:30:06 [error] 38435#0: \*52 open()  
“/home/w/www.foo.com/lib/tpl/default/images/button-css.png” failed (2:  
No such  
file or directory), client: 1.2.3.4, server: [www.foo.com](http://www.foo.com), request: “GET  
/lib/tpl/default/images/button-css.png HTTP/1.1”, host: “[www.foo.com](http://www.foo.com)”,  
referrer: “[http://www.foo.com/wiki/index.php](http://www.foo.com/wiki/index.php)”

It looks like it’s looking for the files in the wrong place?

I tested the same wiki in a vanilla configuration of nginx, where I just  
set  
[www.foo.com](http://www.foo.com) as server\_name etc, and there it works. The directory  
structure  
is the same.

---

<div class="post-metadata">

**Author:** ![Joel\_Dahl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/47e85d/32.png) [@Joel\_Dahl](https://www.ruby-forum.com/u/Joel_Dahl)\
**Post date:** [June 17, 2009, 8:56pm UTC](https://www.ruby-forum.com/t/nginx-configuration-issues/170455/4 "2009-06-17T20:56:48Z")

</div>

On Wed, 2009-06-17 at 21:24 +0400, Igor S. wrote:

> Add
> 
> ```
> server {
> server_name_in_redirect on;
> 
> ```
> 
> otherwise nginx uses “_" as server name in redirect: "http://_/bar/”.

The wiki docs aren’t terribly clear on this (in fact, it seems to  
suggest the opposite - including the default value):

> **[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki...](https://github.com/nginxinc/nginx-wiki)**
>
> ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com

Also, am I correct in assuming the same applies to using wildcards in  
server\_name?

Cliff
