# 403 Error with hostname, but not IP

**URL:** <https://www.ruby-forum.com/t/403-error-with-hostname-but-not-ip/211122>\
**Category:** NGINX\
**Created:** [August 26, 2011, 3:35am UTC](https://www.ruby-forum.com/t/403-error-with-hostname-but-not-ip/211122 "2011-08-26T03:35:16Z")\
**Posts on this page:** 3\
**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:** [August 26, 2011, 3:35am UTC](https://www.ruby-forum.com/t/403-error-with-hostname-but-not-ip/211122/1 "2011-08-26T03:35:16Z")

</div>

Hi.

I’m getting a 403 error when navigating to my Wordpress site served by  
NginX.

Here’s the error message:  
[error] 1140#0: \*1 directory index of “/var/www/mysite.com/public/” is  
forbidden, client: 99.46.122.45, server: [mysite.com](http://mysite.com), request: “GET /  
HTTP/1.1”, host: “[mysite.com](http://mysite.com)”

I have chown www-data:www-data -R and chmod 775 -R to the /var/www/  
[mysite.com/public/\*](http://mysite.com/public/*)

==\> What’s weird is that I CAN navigate to the site if I use "  
12.34.56.78/mysite.com/public" and it all works correctly.

Here’s $ nginx -V  
nginx: nginx version: nginx/1.0.5  
nginx: built by gcc 4.4.3 (Ubuntu 4.4.3-4ubuntu5)  
nginx: TLS SNI support enabled  
nginx: configure arguments: --prefix=/var/www  
–conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid  
–sbin-path=/usr/sbin --user=www-data --group=www-data  
–http-log-path=/var/log/nginx/access.log  
–error-log-path=/var/log/nginx/error.log --with-http\_stub\_status\_module  
–with-ipv6 --with-http\_ssl\_module  
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi  
–http-proxy-temp-path=/var/lib/nginx/proxy  
–http-client-body-temp-path=/var/lib/nginx/body  
–with-http\_geoip\_module  
–with-http\_gzip\_static\_module --with-http\_flv\_module  
–lock-path=/var/lock/nginx.lock  
–http-uwsgi-temp-path=/var/lib/nginx/uwsgi  
–http-scgi-temp-path=/var/lib/nginx/scgi/

Here’s my nginx.conf file:

#### 

worker\_processes 4;

events {  
worker\_connections 1024;  
}

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

```
sendfile on;

#keepalive_timeout 0;
keepalive_timeout 65;

limit_req_zone $binary_remote_addr zone=blitz:10m rate=5r/s;

gzip on;
gzip_comp_level 2;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript 

```

text/xml  
application/xml application/xml+rss text/javascript;

```
include /etc/nginx/backends.conf;
include /etc/nginx/sites-enabled/*;

```

}

##### 

Here’s /etc/nginx/sites-available/mysite.com file

#### 

server {  
listen 80;  
server\_name [www.mysite.com](http://www.mysite.com);  
rewrite ^/(.\*) [http://mysite.com/$1](http://mysite.com/$1) permanent;  
}

server {  
listen 80;

server\_name [mysite.com](http://mysite.com);

root /var/www/mysite.com/public;

access\_log /var/www/mysite.com/access.log;  
error\_log /var/www/mysite.com/error.log;

location / {  
try\_files $uri $uri/ /index.php;  
}

location /search { limit\_req zone=blitz burst=3 nodelay; rewrite ^  
/index.php; }

fastcgi\_intercept\_errors off;

location ~\* .(?:ico|css|js|gif|jpe?g|png)$ {  
expires max;  
#from [WordPress | NGINX](http://wiki.nginx.org/Wordpress)  
#this is in the /etc/nginx/drop\_wp.conf file  
#log\_not\_found off;  
add\_header Pragma public;  
add\_header Cache-Control “public, must-revalidate, proxy-revalidate”;  
}

include php.conf;  
include drop\_wp.conf;  
}

#### 

Here’s the drop\_wp.conf file

#### 

location = /favicon.ico { access\_log off; log\_not\_found off; }  
location ~ /. { access\_log off; log\_not\_found off; deny all; }  
location ~ ~$ { access\_log off; log\_not\_found off; deny all; }

#### 

Any ideas on how to fix it?  
Thanks in advance for your help.

---

<div class="post-metadata">

**Author:** ![Cineron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7c8e57/32.png) [@Cineron](https://www.ruby-forum.com/u/Cineron)\
**Post date:** [August 26, 2011, 6:24am UTC](https://www.ruby-forum.com/t/403-error-with-hostname-but-not-ip/211122/2 "2011-08-26T06:24:11Z")

</div>

Hi

In your try\_files in location / you have $uri/ as your second option.  
This means that it will try to read the URI as a directory. Since you do  
not have an index directive defined it will instead try to list the  
content of the directory, which is not allowed by default.

You need to define an index directive  
[http://wiki.nginx.org/HttpIndexModule#index](http://wiki.nginx.org/HttpIndexModule#index) either in your location  
block or further up.

Posted at Nginx Forum:

> **[Re: 403 Error with hostname, but not IP](https://forum.nginx.org/read.php?2,214315,214317#msg-214317)**
>
> Hi. I'm getting a 403 error when navigating to my Wordpress site served by NginX. Here's the error message: \[error\] 1140#0: \*1 directory index of "/var/www/mysite.com/public/" is forbidden, client: 99.46.122.45, server: mysite.com, request:...

---

<div class="post-metadata">

**Author:** ![Cineron](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/7c8e57/32.png) [@Cineron](https://www.ruby-forum.com/u/Cineron)\
**Post date:** [August 26, 2011, 4:07pm UTC](https://www.ruby-forum.com/t/403-error-with-hostname-but-not-ip/211122/3 "2011-08-26T16:07:03Z")

</div>

Thank you for spotting that error and sending me the link! That solved  
the  
problem.  
I would not have seen that omission for weeks, since I’m so new to  
nginx.
