title: Block direct access to php files (only rewrited) using nginx
body: <p>I have files like Ucp.php Somesite.php and i want to create a rewrite rules for nginx. This is not problematic.</p>
  
  <p>But i also want to block direct access to those php files, so that enetring <a href="http://mysite.com/Ucp.php" rel="nofollow">http://mysite.com/Ucp.php</a> will return 404 Not Found. </p>
  
  <p>There is a solution for apache (using THE_REQUEST), but how can I do this on nginx?</p>
  
  <pre><code>server
  {
          listen 80;
          server_name site.com;
          root /home/site/public_html;
  
          index Main.php;
          rewrite ^/SomeAddr/$ /SomeAddr.php last;
          rewrite ^/SomeOtherAddr/$ /SomeOtherAddr.php last;
  
  
          location ~ \.php$
          {
                  fastcgi_pass unix:/var/run/php-fpm/site_com.sock;
                  include fastcgi.conf;
          }
          include security.conf;
  }
  </code></pre>