Answers.Body: <p>First set your web server up so the full website gets loaded from both the external ports (e.g. 80 and 443) as well as your internal port (let's say 9001).</p>
  
  <p>Then open your index.php file, and add this to the top of it:</p>
  
  <pre class="lang-php prettyprint-override"><code>// Restrict CP access to port 9001
  if (
      $_SERVER['SERVER_PORT'] != 9001 &amp;&amp; 
      isset($_GET['p']) &amp;&amp;
      preg_match('^\/*admin(\/.*)?$/', $_GET['p'])
  ) {
      http_response_code(403);
      echo 'You are not authorized to access this area.';
      exit();
  }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-11-17T11:59:32.873Z
Answers.LastActivityDate: 2015-11-17T11:59:32.873Z
Answers.UserDisplayName: Brandon Kelly
Body: <p>Is it possible to limit access to the Control Panel to a specific HTTP port, which is shielded from public access? We want external visitors to only be able to access the front end site.</p>
  
Tags: <security><authentication>
Title: How can I restrict access to the Control Panel to a single port?
ThreadText: # How can I restrict access to the Control Panel to a single port?
  
  (Asked by: username_0 on 2015-11-17)
  
  Is it possible to limit access to the Control Panel to a specific HTTP port, which is shielded from public access? We want external visitors to only be able to access the front end site.
  
  **Tags:** security, authentication
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-11-17. Score: 2 | Accepted answer
  
  First set your web server up so the full website gets loaded from both the external ports (e.g. 80 and 443) as well as your internal port (let's say 9001).
  
  Then open your index.php file, and add this to the top of it:
  
  ```php
  // Restrict CP access to port 9001
  if (
      $_SERVER['SERVER_PORT'] != 9001 && 
      isset($_GET['p']) &&
      preg_match('^\/*admin(\/.*)?$/', $_GET['p'])
  ) {
      http_response_code(403);
      echo 'You are not authorized to access this area.';
      exit();
  }
  
  ```
  
  
  ---
  
  