# Newbie needs help

**URL:** <https://www.ruby-forum.com/t/newbie-needs-help/245421>\
**Category:** NGINX\
**Created:** [May 30, 2013, 12:02pm UTC](https://www.ruby-forum.com/t/newbie-needs-help/245421 "2013-05-30T12:02:22Z")\
**Posts on this page:** 5\
**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 30, 2013, 12:02pm UTC](https://www.ruby-forum.com/t/newbie-needs-help/245421/1 "2013-05-30T12:02:22Z")

</div>

Hi,  
new in ths nginx, with following config, I want to achieve:

[http://sample.com/](http://sample.com/) render index.html  
[http://sample.com/test](http://sample.com/test), or anything after ‘/’ path, render index.html

server {  
listen 80;  
server\_name [sample.com](http://sample.com) ;  
root /var/www/sample/public\_html;

location / {  
index index.html index.htm;  
}

location ~ ^/.\* {  
index index.html;  
}

}

but when I do this, and got 404 error, anything missing here? Thanks  
Angelo

curl -I [http://sample.com/test](http://sample.com/test)

HTTP/1.1 404 Not Found

Posted at Nginx Forum:

> **[newbie needs help](https://forum.nginx.org/read.php?2,239683,239683#msg-239683)**
>
> Hi, new in ths nginx, with following config, I want to achieve: http://sample.com/ render index.html http://sample.com/test, or anything after '/' path, render index.html server { listen 80; server\_name sample.com ;

---

<div class="post-metadata">

**Author:** ![angelochen960](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@angelochen960](https://www.ruby-forum.com/u/angelochen960)\
**Post date:** [May 30, 2013, 2:26pm UTC](https://www.ruby-forum.com/t/newbie-needs-help/245421/2 "2013-05-30T14:26:05Z")

</div>

Thanks for the reply, it works, and also I read again those references.  
a  
related issue, say:

if somebody enter this url in the browser:  
[http://sample.com/not\_exist\_url](http://sample.com/not_exist_url)

and I’d like to redirect it to

[http://sample.com/](http://sample.com/)

with the try\_files approach, index.html got displayed, that’s right, but  
the  
url in browser still remain as [http://sample.com/not\_exist\_url](http://sample.com/not_exist_url), i’m  
looking  
for a 302 i believe, any suggestions? thanks.

Angelo

Posted at Nginx Forum:

> **[Re: newbie needs help](https://forum.nginx.org/read.php?2,239683,239695#msg-239695)**
>
> Hi, new in ths nginx, with following config, I want to achieve: http://sample.com/ render index.html http://sample.com/test, or anything after '/' path, render index.html server { listen 80; server\_name sample.com ;

---

<div class="post-metadata">

**Author:** ![angelochen960](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@angelochen960](https://www.ruby-forum.com/u/angelochen960)\
**Post date:** [May 30, 2013, 12:25pm UTC](https://www.ruby-forum.com/t/newbie-needs-help/245421/3 "2013-05-30T12:25:44Z")

</div>

On Thursday 30 May 2013 14:02:00 angelochen960 wrote:

> Hi,  
> new in ths nginx, with following config, I want to achieve:
> 
> [http://sample.com/](http://sample.com/) render index.html  
> [http://sample.com/test](http://sample.com/test), or anything after ‘/’ path, render index.html

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

```
  root /var/www/sample/public_html;

  location / {
      try_files /index.html =404;
  }

```

}

> ```
> index index.html;
> 
> ```

Since your config looks incorrect, it seems you are missing  
understanding of how  
nginx works.

You should try to read documentation:

- [How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html)
- [Module ngx\_http\_core\_module](http://nginx.org/r/location)
- [Module ngx\_http\_index\_module](http://nginx.org/r/index)
- [Module ngx\_http\_core\_module](http://nginx.org/r/try_files)

wbr, Valentin V. Bartenev

–

> **[nginx: donation](http://nginx.org/en/donation.html)**

---

<div class="post-metadata">

**Author:** ![angelochen960](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@angelochen960](https://www.ruby-forum.com/u/angelochen960)\
**Post date:** [May 30, 2013, 4:20pm UTC](https://www.ruby-forum.com/t/newbie-needs-help/245421/4 "2013-05-30T16:20:04Z")

</div>

that works, thanks.

Posted at Nginx Forum:

> **[Re: newbie needs help](https://forum.nginx.org/read.php?2,239683,239699#msg-239699)**
>
> Hi, new in ths nginx, with following config, I want to achieve: http://sample.com/ render index.html http://sample.com/test, or anything after '/' path, render index.html server { listen 80; server\_name sample.com ;

---

<div class="post-metadata">

**Author:** ![angelochen960](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/d78d45/32.png) [@angelochen960](https://www.ruby-forum.com/u/angelochen960)\
**Post date:** [May 30, 2013, 3:47pm UTC](https://www.ruby-forum.com/t/newbie-needs-help/245421/5 "2013-05-30T15:47:54Z")

</div>

On Thursday 30 May 2013 16:25:18 angelochen960 wrote:

> the url in browser still remain as [http://sample.com/not\_exist\_url](http://sample.com/not_exist_url), i’m  
> looking for a 302 i believe, any suggestions? thanks.

Yes, you’re looking for an external redirect, that is completely  
different thing. Then this config will serve your needs:

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

```
  root /var/www/sample/public_html;

  location = / {
      try_files /index.html =404;
  }

  location / {
      return 302 /;
  }

```

}

Reference:

- [Module ngx\_http\_rewrite\_module](http://nginx.org/r/return)
- [Module ngx\_http\_core\_module](http://nginx.org/r/try_files)
- [Module ngx\_http\_core\_module](http://nginx.org/r/location)

wbr, Valentin V. Bartenev

–

> **[nginx: donation](http://nginx.org/en/donation.html)**
