title: How to restrict ip access in nginx
body: <p>I want to restrict access by IP for specific php file in Nginx reverse_proxy.
  so in my virtual host path <code>/etc/nginx/sites-available/sub.mydmn.com</code> I have the following configs:</p>
  
  <pre><code>server {
      server_name wwww.sub.mydmn.com sub.mydmn.com;
      root /home/mydmn/;
  
      access_log off;
  
      # Static contents
      location ~* ^.+.(png|mp4|jpeg)$ {
          expires max;
      }
  
      # Limit IP access
      location = /mine.php {
          allow &lt;MyIP_Here&gt;;
          deny all;
          return 404;
      }
  
      # Dynamic content, forward to Apache
      location / {
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header Host $host;
          proxy_pass http://127.0.0.1:8080;
      }
  }
  
  # Deny server with IP access!
  server {
      listen 80 default_server;
      server_name _;
      location / {
      return 403;
      }
  }
  </code></pre>
  
  <p>But when I start the server, Nginx blocks all IPs for <code>mine.php</code>.
  What is the problem?</p>