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:
server {
listen 80;
client_max_body_size 50M;
server_name 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/;
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
(no duplicate content)
Thanks for your help
Bye
Posted at Nginx Forum:
2012/4/6 zuckbin [email protected]:
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,
…
Then you should tell your app to link static contents at
static.mydomain.com instead of mydomain.com and then add its server
block.
What is the server block ?
Posted at Nginx Forum:
On Tuesday 10 April 2012 11:47:12 zuckbin wrote:
What is the server block ?
http://nginx.org/r/server
wbr, Valentin V. Bartenev
ok, can i do this ?
server {
listen ip:80;
server_name 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:
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
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:
If is Evil… when used in location context | NGINX
Pitfalls and Common Mistakes | NGINX
How nginx processes a request
Module ngx_http_core_module
[…]
return 404;
}
}
Then you will understand how to write good configuration:
server {
listen ip:80;
server_name 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