title: subdomains + nginx + reverse proxy + jenkins + gitlab
body: <p>Searching the internet for the complete guide and explanation on how to run website + jenkins + gitlab like so:</p>
  
  <ul>
  <li>Jenkins @ jenkins.domain.com</li>
  <li>GitLab @ gitlab.domain.com</li>
  <li>static website @ domain.com</li>
  </ul>
  
  <p>ie Specific services on a server and have access to them via subdomains, I haven't found and answer.</p>
  
  <p>We are running ubuntu, nginx and have a domain name example.com and an A record pointing to our ip address 111.111.111.111</p>
  
  <p>We can see the nginx welcome page.</p>
  
  <p>How are the subdomains resolved? Where to create them?
  Can our server become a DNS?
  What should be the final nginx conf?</p>
  
  <p>This one is wrong, since it needs to serve static website and tries to serve static files for jenkins and that results in a 404.</p>
  
  <pre><code>server {
    access_log        logs/landing.access.log;
    server_name       example.com;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  Host $host;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  
    location / {
      root /var/www/html/landing;
      index index.html;
    }
  
    location /app {
      proxy_pass      http://localhost:9981;
    }
  
    location ^~ /jenkins {
      proxy_pass          http://127.0.0.1:9990;
      proxy_read_timeout  90;
  
      # Fix the “It appears that your reverse proxy set up is broken" error.
      proxy_redirect      http://127.0.0.1:9990 $scheme://example.com;
  
      # Optionally, require HTTP basic auth.
      # auth_basic "Please authenticate to use Jenkins";
      # auth_basic_user_file /opt/nginx/htpasswd;
    }
  }
  </code></pre>
  
  <p>Should there be another server block then?</p>
  
  <pre><code>server {
    access_log        logs/jenkins.access.log;
    server_name       jenkins example.com;
    proxy_set_header  X-Real-IP $remote_addr;
    proxy_set_header  Host $host;
    proxy_set_header  X-Forwarded-For $proxy_add_x_forwarded_for;
  
    proxy_pass          http://127.0.0.1:9990;
  }
  </code></pre>
  
  <p>But this one gives a 404 for a different reason, I assume this 2nd block clashes with the first one, as I am trying to access it via example.com not subdomain.example.com. And subdomain.example.com is not resolved.</p>