# Problem with virtual host settings

**URL:** <https://www.ruby-forum.com/t/problem-with-virtual-host-settings/203878>\
**Category:** NGINX\
**Created:** [March 1, 2011, 6:10am UTC](https://www.ruby-forum.com/t/problem-with-virtual-host-settings/203878 "2011-03-01T06:10:36Z")\
**Posts on this page:** 2\
**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 1, 2011, 6:10am UTC](https://www.ruby-forum.com/t/problem-with-virtual-host-settings/203878/1 "2011-03-01T06:10:36Z")

</div>

So I have a info.php page which is located on the folder  
/var/www/nginx-default, however when I go to my ip address/info.php, it  
always redirects me to this site:[http://www.iana.org/domains/example/is](http://www.iana.org/domains/example/is)  
this because I have a virtual host that I called example? Here is my  
config for the example website:  
server {  
listen 80;  
server\_name [www.example.com](http://www.example.com);  
rewrite ^/(.\*) [http://example.com/$1](http://example.com/$1) permanent;  
}

server {  
listen 80;  
server\_name [example.com](http://example.com);

```
 access_log /var/www/example.com/logs/access.log;
 error_log /var/www/example.com/logs/error.log;

 location / {
      root /var/www/example.com/public/;
      index index.html;
      }

```

}

As I don’t have a domain name yet and I can only access the server via  
terminal. The way I access this site via browser is by changing my  
/etc/hosts in my macbook so that [example.com](http://example.com) is mapped to my server IP  
address. however now when I do xxx.xxx.xxx.xxx/info.php in my macbook  
browser it redirects me to that site I posted above, when I access  
[example.com](http://example.com) from my macbook it works just fine.

---

<div class="post-metadata">

**Author:** ![aditya\_h](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/e36b37/32.png) [@aditya\_h](https://www.ruby-forum.com/u/aditya_h)\
**Post date:** [March 1, 2011, 8:55am UTC](https://www.ruby-forum.com/t/problem-with-virtual-host-settings/203878/2 "2011-03-01T08:55:51Z")

</div>

Hello,

Short answers:

- Add [www.example.com](http://www.example.com) to your /etc/hosts  
OR
- In your second server block, change “listen 80” to “listen 80  
default;”.

Both should work.

Now, to understand why : have a look there  
[http://nginx.org/en/docs/http/request\_processing.html](http://nginx.org/en/docs/http/request_processing.html)

A.
