title: Creating virtualhost in nginx to host NodeJS app
body: <p>Previously, I have hosted my NodeJS application with Apache proxy with following configuration in virtual-host.</p>
  
  <pre><code>&lt;VirtualHost *:80&gt;
    ServerName api.mydomain.com
    ProxyPreserveHost On
    ProxyPass / http://localhost:8090/
    ProxyPassReverse / http://localhost:8090/
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>Now I have moved to <code>NGINX</code> because of GitLab dependency.</p>
  
  <p>Now the virtual-host under <code>/etc/nginx/sites-available/api.mydomain.com</code></p>
  
  <pre><code>server {
      listen 80;
  
      server_name api.mydomain.com;
  
      location / {
          proxy_pass http://localhost:8090;
          proxy_http_version 1.1;
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_set_header Host $host;
          proxy_cache_bypass $http_upgrade;
       }
  }
  </code></pre>
  
  <p>But the domain loads the main host content, not the nodejs app.</p>
  
  <p>nginx version <code>nginx/1.10.1</code>, ubuntu version <code>16.04</code></p>
  
  <p>Below is the only another virtual-host which I have for gitlab,</p>
  
  <pre><code>upstream gitlab-workhorse {
    server unix:/var/opt/gitlab/gitlab-workhorse/socket;
  }
  
  ## Normal HTTP host
  server {
    ## Either remove "default_server" from the listen line below,
    ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
    ## to be served if you visit any address that your server responds to, eg.
    ## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
    listen 0.0.0.0:80 default_server;
    listen [::]:80 default_server;
    server_name gitlab.mydomain.com
    server_tokens off; ## Don't show the nginx version number, a security best practice
    root /opt/gitlab/embedded/service/gitlab-rails/public;
  
    ## See app/controllers/application_controller.rb for headers set
  
    ## Individual nginx logs for this GitLab vhost
    access_log  /var/log/nginx/gitlab_access.log;
    error_log   /var/log/nginx/gitlab_error.log;
  
    location / {
      client_max_body_size 0;
      gzip off;
  
      ## https://github.com/gitlabhq/gitlabhq/issues/694
      ## Some requests take more than 30 seconds.
      proxy_read_timeout      300;
      proxy_connect_timeout   300;
      proxy_redirect          off;
  
      proxy_http_version 1.1;
  
      proxy_set_header    Host                $http_host;
      proxy_set_header    X-Real-IP           $remote_addr;
      proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
      proxy_set_header    X-Forwarded-Proto   $scheme;
  
      proxy_pass http://gitlab-workhorse;
    }
  }
  </code></pre>