使用独角兽配置子域名nginx

时间:2012-03-31 18:34:41

标签: nginx unicorn

我在linode中使用nginx + unicorn。

这是我的 nginx.conf

upstream unicorn {
  server unix:/tmp/unicorn.mydomain.sock fail_timeout=0;
}
server {
  listen 80 default;
  server_name  mydomain.com;
   keepalive_timeout 5;

  root /home/hyperrjas/mydomain.com/current/public;

  location / {
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # this is required for HTTPS:
    # proxy_set_header X-Forwarded-Proto https;
    proxy_set_header Host $http_host;
    proxy_redirect off;
    proxy_pass http://unicorn;
  }

      location ~ ^/(assets)/  {
                                root /home/hyperrjas/mydomain.com/current/public;
                                gzip_static on; # to serve pre-gzipped version
                                expires max;
                                add_header  Cache-Control public;
                               }

  error_page 500 502 503 504 /500.html;
}

我想添加4个子域名:

imagescdn1.mydomain.com 
imagescdn2.mydomain.com  
imagescdn3.mydomain.com  
imagescdn4.mydomain.com

我该怎么做?

1 个答案:

答案 0 :(得分:3)

您应该使用regex作为server_name指令,例如:

server {
    server_name   mydomain.com  ~^imagescdn\d+\.mydomain\.com$;
}

有关详细信息,请参阅原始文档herehere