title: how to setup subdomain in following environment: nginx, supervisor, django, gunicorn?
body: <p>I have a django app setup with nginx+gunicorn+supervisor and its working fine. But i need to create a subdomain for staging or development like "dev.domain.com". I have added another server block in nginx.conf for my subdomain. But my subdomain url was always pointing main domain site. so i changed the port no in proxy_pass as suggested on other posts. but due to gunicorn and supervisord i needed to add another conf file for this subdomain in "/etc/supervisord/conf.d/subdomain.conf" but when i reload supervisord its not able to start my subdomain program. below is my nginx.conf, subdomain.conf, script.sh:
  <strong>nginx.conf</strong></p>
  
  <pre><code>http {
  include       mime.types;
  default_type  application/octet-stream;
  
  #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
  #                  '$status $body_bytes_sent "$http_referer" '
  #                  '"$http_user_agent" "$http_x_forwarded_for"';
  
  #access_log  logs/access.log  main;
  
  sendfile        on;
  #tcp_nopush     on;
  
  #keepalive_timeout  0;
  keepalive_timeout  65;
  
  gzip  on;
  gzip_static  on;
  gzip_types application/x-javascript text/css text/html application/json text/css text/json;
  
  server {
  listen   80;
  server_name domain_name
  # no security problem here, since / is alway passed to upstream
  root /home/path/to/project/base
  # serve directly - analogous for static/staticfiles
  location /static/ {
      # if asset versioning is used
      if ($query_string) {
          expires max;
      }
      autoindex off;
      root /home/path/to/static/;
  }
  location / {
      proxy_pass_header Server;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Scheme $scheme;
      proxy_connect_timeout 10;
      proxy_read_timeout 10;
  proxy_pass http://localhost:8000/;
      proxy_set_header X-Forwarded-For $remote_addr;
  }
  }
  
  server {
  listen   80;
  server_name subdomain_name
  # no security problem here, since / is alway passed to upstream
  root /home/path/to/subdomain_directory(which is different, you can say it is fully differnt project which i want to run as development project);
  # serve directly - analogous for static/staticfiles
  
  
  location / {
      proxy_pass_header Server;
      proxy_set_header Host $http_host;
      proxy_redirect off;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Scheme $scheme;
      proxy_connect_timeout 10;
      proxy_read_timeout 10;
      proxy_pass http://localhost:9000/;
      proxy_set_header X-Forwarded-For $remote_addr;
  }
  }
  }
  </code></pre>
  
  <p><strong>script.sh</strong></p>
  
  <pre><code>set -e
  NUM_WORKERS=4
  # user/group to run as
  USER=user_name
  #GROUP=your_unix_group
  cd /home/path/to/subdomain_base
  source subdomain_virtualenv_activation
  LOGFILE=log_file_path
  LOGDIR=$(dirname $LOGFILE)
  test -d $LOGDIR || mkdir -p $LOGDIR
  exec virtualenvironment/bin/gunicorn_django -w $NUM_WORKERS \
  --user=$USER --log-level=debug \
  --log-file=$LOGFILE 2&gt;&gt;$LOGFILE
  </code></pre>
  
  <p><strong>subdomain.conf</strong></p>
  
  <pre><code>[program:programname]
  directory = /home/path/to/subdomainbase/
  user = user_name
  command = /home/path/to/script.sh
  stdout_logfile = /home/path/to/log
  stderr_logfile = /home/path/to/log
  </code></pre>
  
  <p>I have a procfile too as suggested in gunicorn which is in base directory
  <strong>Procfile</strong></p>
  
  <pre><code>./manage.py runserver_plus 0.0.0.0:$PORT
  </code></pre>
  
  <p>Ok so these are my configurations. Please check where i am doing the wrong thing. I just want to run my development server as a different project but under same domain as subdomain. after all this whatever changes i am doing, main domain is working fine wioth the same process. Please let me know if you need more info on this error.</p>