# Serve static content on static domain

**URL:** <https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638>\
**Category:** NGINX\
**Created:** [April 6, 2012, 3:42pm UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638 "2012-04-06T15:42:27Z")\
**Posts on this page:** 7\
**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:** [April 6, 2012, 3:42pm UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/1 "2012-04-06T15:42:27Z")

</div>

Hi,

How to serve static content on static domain cookieless.

I use ngix to serve static content then apache to dynamic content.

Want to serve on [static.mydomain.com](http://static.mydomain.com) all static content: jpeg, css, js,  
…

Here my actual conf:

server {  
listen 80;  
client\_max\_body\_size 50M;  
server\_name [www.mydoamin.com](http://www.mydoamin.com);  
access\_log /var/log/nginx/localhost.access\_log main;  
error\_log /var/log/nginx/localhost.error\_log info;  
location / {  
proxy\_pass [http://IP:8080/](http://IP:8080/);  
proxy\_redirect default;  
proxy\_set\_header Host $host;  
proxy\_set\_header X-Real-IP $remote\_addr;  
proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for;

}  
location ~\*  
^.+.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js)$  
{  
root /home/www/domain.com;  
expires 30d;  
add\_header Pragma public;  
add\_header Cache-Control “public”;  
}  
}

Want all my static content will be delivered only with:  
[static.domain.com](http://static.domain.com)  
(no duplicate content)

Thanks for your help  
Bye

Posted at Nginx Forum:

> **[serve static content on static domain](https://forum.nginx.org/read.php?2,225020,225020#msg-225020)**
>
> Hi, How to serve static content on static domain cookieless. I use ngix to serve static content then apache to dynamic content. Want to serve on static.mydomain.com all static content: jpeg, css, js, ... Here my actual conf:

---

<div class="post-metadata">

**Author:** ![zuckbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zuckbin](https://www.ruby-forum.com/u/zuckbin)\
**Post date:** [April 6, 2012, 3:47pm UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/2 "2012-04-06T15:47:25Z")

</div>

2012/4/6 zuckbin [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hi,
> 
> How to serve static content on static domain cookieless.
> 
> I use ngix to serve static content then apache to dynamic content.
> 
> Want to serve on [static.mydomain.com](http://static.mydomain.com) all static content: jpeg, css, js,  
> …

Then you should tell your app to link static contents at  
[static.mydomain.com](http://static.mydomain.com) instead of [mydomain.com](http://mydomain.com) and then add its server  
block.

---

<div class="post-metadata">

**Author:** ![zuckbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zuckbin](https://www.ruby-forum.com/u/zuckbin)\
**Post date:** [April 10, 2012, 9:47am UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/3 "2012-04-10T09:47:36Z")

</div>

What is the server block ?

Posted at Nginx Forum:

> **[Re: serve static content on static domain](https://forum.nginx.org/read.php?2,225020,225098#msg-225098)**
>
> Hi, How to serve static content on static domain cookieless. I use ngix to serve static content then apache to dynamic content. Want to serve on static.mydomain.com all static content: jpeg, css, js, ... Here my actual conf:

---

<div class="post-metadata">

**Author:** ![zuckbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zuckbin](https://www.ruby-forum.com/u/zuckbin)\
**Post date:** [April 10, 2012, 10:52am UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/4 "2012-04-10T10:52:41Z")

</div>

On Tuesday 10 April 2012 11:47:12 zuckbin wrote:

> What is the server block ?

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#server)**
>
> This directive appeared in version 1.11.8.

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![zuckbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zuckbin](https://www.ruby-forum.com/u/zuckbin)\
**Post date:** [April 11, 2012, 9:06am UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/5 "2012-04-11T09:06:58Z")

</div>

ok, can i do this ?

server {  
listen ip:80;  
server\_name [yourserver.com](http://yourserver.com);  
root /srv/http/nginx/yourserver.com;  
access\_log logs/yourserver.com.access.log;  
location / {  
index index.html;  
charset utf-8;  
}

```
    }

    }

    server {
    listen ip:80;
    server_name static.static-yourserver.com;
    root /srv/http/nginx/yourserver.com;
    location / {
            if ($request_filename ~

```

“.(jpg|css|gif|png|swf|ico|mp3)$”) {  
break;  
}  
return 404;  
}  
}

Posted at Nginx Forum:

> **[Re: serve static content on static domain](https://forum.nginx.org/read.php?2,225020,225165#msg-225165)**
>
> Hi, How to serve static content on static domain cookieless. I use ngix to serve static content then apache to dynamic content. Want to serve on static.mydomain.com all static content: jpeg, css, js, ... Here my actual conf:

---

<div class="post-metadata">

**Author:** ![zuckbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zuckbin](https://www.ruby-forum.com/u/zuckbin)\
**Post date:** [April 11, 2012, 12:36pm UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/6 "2012-04-11T12:36:48Z")

</div>

On Wednesday 11 April 2012 14:31:21 Valentin V. Bartenev wrote:  
[…]

> ```
> location \.(?:jpg|css|gif|png|swf|ico|mp3)$ {
> 
> }
> 
> ```

Oops,

location ~ .(?:jpg|css|gif|png|swf|ico|mp3)$ {

}

wbr, Valentin V. Bartenev

---

<div class="post-metadata">

**Author:** ![zuckbin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/z/ce7236/32.png) [@zuckbin](https://www.ruby-forum.com/u/zuckbin)\
**Post date:** [April 11, 2012, 12:31pm UTC](https://www.ruby-forum.com/t/serve-static-content-on-static-domain/218638/7 "2012-04-11T12:31:51Z")

</div>

On Wednesday 11 April 2012 11:06:21 zuckbin wrote:

> ok, can i do this ?

Sure, you can. But, please, take a look at this links:

[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/IfIsEvil)  
[GitHub - nginxinc/nginx-wiki: ARCHIVED -- Source for the now archived NGINX Wiki section of https://www.nginx.com · GitHub](http://wiki.nginx.org/Pitfalls)  
[How nginx processes a request](http://nginx.org/en/docs/http/request_processing.html)  
[Module ngx\_http\_core\_module](http://nginx.org/r/location)

[…]

> ```
> return 404;
> }
> }
> 
> ```

Then you will understand how to write good configuration:

server {  
listen ip:80;  
server\_name [static.static-yourserver.com](http://static.static-yourserver.com);  
root /srv/http/nginx/yourserver.com;

```
    location / {
   return 404;
    }

    location \.(?:jpg|css|gif|png|swf|ico|mp3)$ {

    }

```

}

wbr, Valentin V. Bartenev
