title: Setting 2 sites in a Nginx server with gunicorn + django using systemD service
body: <p>I am following the tutorial:
  <a href="http://www.obeythetestinggoat.com/book/chapter_09.html" rel="nofollow">http://www.obeythetestinggoat.com/book/chapter_09.html</a></p>
  
  <p>So, i have two sites in DigitalOcean with <strong>nginx</strong> and <strong>gunicorn</strong>, one for stage and the normal one... <strong>stage.nossalista.tk</strong> and <strong>nossalista.tk</strong>, first i manage to successfully deploy and run the stage one, but after upload the normal and added another systemd service for my normal one, everything stops working.. i gonna put all my configs and hope you guys give me some hints were may be the problem....</p>
  
  <p>im getting error 400 from the nossalista.tk and 502 for my stage.nossalista.tk</p>
  
  <p>[UPDATE]: I was able to access the site only in stage.nossalista.tk:9000 .... hope this helps who wants to help me</p>
  
  <p>First i did is configure the </p>
  
  <blockquote>
    <p>/etc/nginx/sites-available/stage.nossalista.tk:</p>
  </blockquote>
  
  <pre><code>server {
      listen 80;
      server_name nossalista.tk;
  
      location /static {
          alias /home/tyago/sites/nossalista.tk/static;
      }
  
      location / {
          proxy_set_header Host $host;
          proxy_pass http://unix:/tmp/nossalista.tk.socket;
      }
  }
  </code></pre>
  
  <p>Second i configure the service for this stage site in </p>
  
  <blockquote>
    <p>/etc/systemd/system/gunicorn.service:</p>
  </blockquote>
  
  <pre><code>[Unit]
  Description=Gunicorn server for stage.nossalista.tk
  After=network.target
  
  [Service]
  User=tyago
  Group=www-data
  WorkingDirectory=/home/tyago/sites/stage.nossalista.tk/source
  ExecStart=/home/tyago/sites/stage.nossalista.tk/virtualenv/bin/gunicorn --workers 3 --bind unix:/tmp/stage.nossalista.tk.socket superlists.wsgi:application
  Restart=always
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>and then configure my socket service in </p>
  
  <blockquote>
    <p>/etc/systemd/system/gunicorn.socket:</p>
  </blockquote>
  
  <pre><code>[Unit]
  Description=gunicorn socket
  
  [Socket]
  ListenStream=/run/gunicorn/socket
  ListenStream=0.0.0.0:9000
  ListenStream=[::]:8000
  
  [Install]
  WantedBy=sockets.target
  </code></pre>
  
  <p>and then the gunicorn.conf file in
   (tyago is my user)</p>
  
  <blockquote>
    <p>/usr/lib/tmpfiles.d/gunicorn.conf</p>
  </blockquote>
  
  <pre><code>d /run/gunicorn 0755 tyago tyago  -
  </code></pre>
  
  <p>After i enable both with:</p>
  
  <pre><code>systemctl enable gunicorn.service
  systemctl enable gunicorn.socket
  systemctl start gunicorn.service
  systemctl start gunicorn.socket
  </code></pre>
  
  <p>after reboot the server i was able to access stage.nossalista.tk. Great! 
  but the problem was when put the normal site up
  i make another service in systemd, this time called </p>
  
  <blockquote>
    <p>gunicorn-nossalista.tk.service:</p>
  </blockquote>
  
  <pre><code>[Unit]
  Description=Gunicorn server for www.nossalista.tk
  After=network.target
  
  [Service]
  User=tyago
  Group=www-data
  WorkingDirectory=/home/tyago/sites/nossalista.tk/source
  ExecStart=/home/tyago/sites/nossalista.tk/virtualenv/bin/gunicorn --workers 3 --bind unix:/tmp/nossalista.tk.socket superlists.wsgi:application
  Restart=always
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>and configured in </p>
  
  <blockquote>
    <p>/etc/nginx/sites-available/nossalista.tk as:</p>
  </blockquote>
  
  <pre><code>[Unit]
  Description=Gunicorn server for www.nossalista.tk
  After=network.target
  
  [Service]
  User=tyago
  Group=www-data
  WorkingDirectory=/home/tyago/sites/nossalista.tk/source
  ExecStart=/home/tyago/sites/nossalista.tk/virtualenv/bin/gunicorn --workers 3 --bind unix:/tmp/nossalista.tk.socket superlists.wsgi:application
  Restart=always
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>my systemctl status of the gunicorn.service , gunicorn.socket and gunicorn-nossalista.tk.serice are all Active </p>
  
  <p>checking my error log of nginx i saw that only my stage file was logging there with the following error: </p>
  
  <blockquote>
    <p>Nginx error log</p>
  </blockquote>
  
  <pre><code>2016/09/11 21:16:17 [crit] 3173#3173: *39 connect() to unix:/tmp/stage.nossalista.tk.socket failed (2: No such file or directory) while connecting to upstream, client: 189.34.5.XXX, server: stage.nossalista.tk, request: "GET / HTTP/1.1", upstream: "http://unix:/tmp/stage.nossalista.tk.socket:/", host: "stage.nossalista.tk"
  </code></pre>
  
  <p>ok i change the socket to work with the normal site so probally my error is that i dont have a socket for stage.nossalista ... BUT <strong>why i not see any log error message from my normal site</strong> in error.log if i configured correct the <em>/etc/nginx/sites-enabled/nossalista.tk</em> ? in access log i got this when i access via normal site(nossalista.tk)</p>
  
  <blockquote>
    <p>Access Nginx log:</p>
  </blockquote>
  
  <pre><code>189.34.5.XXX - - [11/Sep/2016:21:53:30 +0000] "GET / HTTP/1.1" 400 37 "-" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:48.0) Gecko/20100101 Firefox/48.0"
  </code></pre>
  
  <p>i know that something is really strange there but cant find why im getting error 400 if i have it in sites-enabled/nossalista.tk all configuration correct pointing to the right socket and all that ....</p>
  
  <p>If you guys help me i would be very great full and i would help anyone with similar errors... i just need some help to get it work!</p>
  
  <blockquote>
    <p>my sudo nginx -t:</p>
  </blockquote>
  
  <pre><code>nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
  </code></pre>
  
  <p>i really dont know what to check more .... if you guys have some hints that would be Very Very NICE !!! </p>
  
  <p>i think my problem is in the socket ... probally i need to have 2 sockets but dont know how to do it !</p>
  
  <p>TY and sory for this big big question....</p>