0

I'm trying to setup a wildcard static domain. My server hosts several domains, so i'd rather have one config for all of them, without having to manually add each and every one. so far i have this...

server {
    server_name static.* www.static.*;

    root /var/web/$host/;

    access_log off;
    error_log off;

    location ~* \.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|exe|html|htm|txt|css|js) {
            add_header        Cache-Control public;
            add_header        Cache-Control must-revalidate;
            expires           7d;
    }
    location  / {
            deny all;
    }

}

all files are stored in /var/web/example.com/ in that format, including subdomains /var/web/subdomain.example.com/

This domain is for static content (only images/css/js etc) and i want the root to be the same as the normal site, just it only allows the static files (hence why php fpm isnt in here)

There arent any nginx errors, but i get 404's, i have a feeling it's to do with root /var/web/$host/; Any ideas?

4

2 回答 2

0

我会尝试

root /var/web/$http_host/;

而且我会尝试使用一个固定的域名(比如 www.static.whatever.com),看看我是否可以访问至少一个静态文件。然后我会继续为这个问题增加更多的自由度。

另外,我会投入

listen 80;

只想确认一下。

于 2013-11-03T14:28:41.033 回答
0

谷歌搜索了一段时间让我知道:http: //nginx.org/en/docs/http/server_names.html

我发现我可以在 server_name 中执行正则表达式。所以这对我有用:

server {
    listen 80;
    server_name ~^static\.(?<domain>.+)$;

    root /var/web/$domain/;

    access_log off;
    error_log off;

    location ~* \.(jpg|jpeg|gif|png|bmp|ico|pdf|flv|swf|exe|html|htm|txt|css|js) {
            add_header        Cache-Control public;
            add_header        Cache-Control must-revalidate;
            expires           7d;
    }
    location  / {
            deny all;
    }

}

于 2013-11-03T14:43:14.493 回答