title: change localhost hostname in nginx
body: <p>I have multiple local sites and I want to configure nginx to have a different host of each website.</p>
  
  <p>In /var/www I have 2 sites: site1 and site2</p>
  
  <p>Then in /etc/nginx/sites-available/ I created 2 different configurations server for each one. I have the files site1 and site2 which content is like:</p>
  
  <pre><code>server {
          listen 80;
  
          root /var/www/site1;
          index index.html index.htm;
  
          server_name localhost;
  
          location / {
                  try_files $uri $uri/ /index.html;
          }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>server {
              listen 7777;
  
              root /var/www/site2;
              index index.html index.htm;
  
              server_name localhost;
  
              location / {
                      try_files $uri $uri/ /index.html;
              }
      }
  </code></pre>
  
  <p>I access to them with <code>http://localhost:80</code> for site1 and <code>http://localhost:7777</code> for site2. That works perfectly. I also could add the hostname in /etc/hosts like this:</p>
  
  <pre><code>127.0.0.1 localhost site1 site2
  </code></pre>
  
  <p>and I could access them with <code>http://site1:80</code> and <code>http://site2:7777</code>. But I have to access always to the port number. I want to access them by <code>http://site1</code> and <code>http://site2</code>.</p>
  
  <p>Is there a solution to do that ?</p>