title: How to start nginx via different port(other than 80)
body: <p>Hi I am a newbie on nginx, I tried to set it up on my server(running Ubuntu 4),  which already has apache running.</p>
  <p>So after I <code>apt-get install</code> it, I tried to start nginx. Then I get the message like this:</p>
  <pre><code>Starting nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  configuration file /etc/nginx/nginx.conf test is successful
  [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
  [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
  [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
  [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
  [emerg]: bind() to 0.0.0.0:80 failed (98: Address already in use)
  </code></pre>
  <p>That makes sense as Apache is using port 80.</p>
  <p>Then I tried to modify <code>nginx.conf</code>, I reference some articles, so I changed it like so:</p>
  <pre><code>   server {
  
          listen       8080;
  
          location / {
           proxy_pass  http://xx.xx.xx.xx:9500;
           proxy_set_header   Host             $host:8080;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header Via    &quot;nginx&quot;;
          }
   
  </code></pre>
  <p>After saving this and try to start nginx again,  I still get the same error as previously.  I cannot really find a related post about this, could any good people shred some light?</p>
  <p><strong>I should post all the content in conf here:</strong></p>
  <pre><code>user www-data;
  worker_processes  1;
  
  error_log  /var/log/nginx/error.log;
  pid        /var/run/nginx.pid;
  
  events {
      worker_connections  1024;
      # multi_accept on;
  }
  
  http {
      include       /etc/nginx/mime.types;
  
      access_log  /var/log/nginx/access.log;
  
      sendfile        on;
      #tcp_nopush     on;
  
      #keepalive_timeout  0;
      keepalive_timeout  65;
      tcp_nodelay        on;
  
      gzip  on;
      gzip_disable &quot;MSIE [1-6]\.(?!.*SV1)&quot;;
  
      include /etc/nginx/conf.d/*.conf;
      include /etc/nginx/sites-enabled/*;
  
     server {
  
          listen       81;
  
          location / {
           proxy_pass  http://94.143.9.34:9500;
           proxy_set_header   Host             $host:81;
           proxy_set_header   X-Real-IP        $remote_addr;
           proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
           proxy_set_header Via    &quot;nginx&quot;;
          }
  
  
      }
  }
  
   mail {
        See sample authentication script at:
        http://wiki.nginx.org/NginxImapAuthenticateWithApachePhpScript
   
        auth_http localhost/auth.php;
        pop3_capabilities &quot;TOP&quot; &quot;USER&quot;;
        imap_capabilities &quot;IMAP4rev1&quot; &quot;UIDPLUS&quot;;
   
       server {
           listen     localhost:110;
           protocol   pop3;
           proxy      on;
       }
   
       server {
           listen     localhost:143;
           protocol   imap;
           proxy      on;
       }
   }
  </code></pre>
  <p>Basically,  I changed nothing except adding the server part.</p>