2012-03-31 89 views
1

我在linode中使用nginx +獨角獸。用獨角獸配置子域nginx

這是我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 

我該怎麼辦呢?

回答

3

您應該使用正則表達式對於server指令,即是這樣的:

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

參考原始文件herehere以獲取更多信息。

+0

woow謝謝你的工作正常:D非常感謝你 – hyperrjas 2012-03-31 18:56:28

+0

是的,你可以將www.mydomain.com添加到列表中:server_name mydomain.com www.mydomain.com〜^ imagescdn \ d + \。mydomain \ .COM $; – BluesRockAddict 2012-03-31 18:58:30