title: Iptables rules for nginx with php-fpm
body: <p>I am setting up iptables rules on the server where nginx and php-fpm are running. I have allow both 80 and 443 ports but as I see there are also addiitonal connections to higher ports that are blocked.</p>
  
  <p>Sample output of </p>
  
  <p><em>netstat -anpn | grep -v ":80"</em></p>
  
  <pre><code>tcp        0      1 10.0.0.1:8109       10.1.2.24:29837     SYN_SENT    19834/nginx: worker
  tcp        0      1 10.2.3.45:31890     10.0.0.1:26701      SYN_SENT    17831/nginx: worker
  </code></pre>
  
  <p>10.0.0.1 is server IP, others are clients.</p>
  
  <p>My iptables rules:</p>
  
  <pre><code>iptables -A INPUT -i lo -j ACCEPT
  iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
  iptables -A INPUT -p tcp --dport 443 -j ACCEPT
  iptables -A INPUT -p tcp --dport 80 -j ACCEPT
  iptables -P INPUT DROP
  iptables -P OUTPUT ACCEPT
  </code></pre>
  
  <p>Can someone explain:</p>
  
  <ol>
  <li><p>Why do nginx uses ports different from standard 80 and 443.</p></li>
  <li><p>What is this additional ports range?</p></li>
  <li><p>How to properly allow connections to nginx with iptables?</p></li>
  </ol>
  
  <p>Thanks in advance!</p>