简体   繁体   中英

configure subdomain nginx with unicorn

I am using nginx + unicorn in linode.

This is my 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;
}

I want to add 4 subdomains:

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

How can I do it?

You should use regex for server_name directive, ie something like this:

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

Refer to original documentation here and here for more information.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM