title: nginx reverse proxy for nodejs express,works with ip address but not domain name
body: <p>I have nginx works as a reverse proxy for a node.js express application.
   I can access to  </p>
  
  <pre><code>http://ip:8081/data/emoji.json 
  </code></pre>
  
  <p>but it doesn't work with domain name</p>
  
  <pre><code> http://domain_name/data/emoji.json
  </code></pre>
  
  <p>doesn't work.
  Here is the configuration of nginx:</p>
  
  <pre><code>server {
      listen 80 default_server;
      listen [::]:80 default_server;
  
      index index.html index.htm index.nginx-debian.html;
      server_name domain_name;
  
      location / {
              # First attempt to serve request as file, then
              # as directory, then fall back to displaying a 404.
              try_files $uri $uri/ =404;
              proxy_pass http://127.0.0.1:8081;
              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;
          }
  
          location /mongo {
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header X-Forwarded-Proto https;
              proxy_set_header Host $http_host;
              proxy_redirect off;
  
              if (!-f $request_filename) {
                  rewrite /mongo/(.+) /$1 break;
                  proxy_pass http://127.0.0.1:28017;
                  break;
              }
          }
  }
  </code></pre>