Browse Source

0177: Install and Configure nginx on Windows

i12bretro 3 năm trước cách đây
mục cha
commit
64b46466cf
1 tập tin đã thay đổi với 143 bổ sung0 xóa
  1. 143 0
      0177.html

+ 143 - 0
0177.html

@@ -0,0 +1,143 @@
+    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
+      <head>
+        <title>Install and Configure nginx on Windows</title>
+        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+								<script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
+				        <script type="text/javascript">
+          $(function(){
+            $('textarea').each(function(i,e){
+              theTextarea = $(this);
+              theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
+            });
+
+            $('li').each(function(i,e){
+              var uuid = 'li_' + Math.floor(Math.random() * Math.floor(1000000)).toString() + '_' + i.toString();
+              $(this).contents().wrap('<span id="'+ uuid +'"><label for="cb_'+ uuid +'"></label></span>');
+              $(this).prepend('<input type="checkbox" class="completeBox" id="cb_' + uuid +'" rel="'+ uuid +'" />')
+            });
+
+            $('code,div.codeBlock,textarea.codeBlock').each(function(i,e){
+              theElement = $(this);
+              var lines = theElement.html().split("\n");
+              theElement.empty();
+              for(l=0;l<lines.length;l++){
+                if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
+									                  theElement.append('<input type="image" src="images/clipboard.png" value="" class="copy-text" rel="copy_'+ i +'_'+ l +'" data-clipboard-text="'+ lines[l].replace(/"/g, '&quot;') +'" /><span id="copy_'+ i +'_'+ l +'">'+ lines[l] +'</span>');
+									                } else {
+                  theElement.append(lines[l]);
+                }
+              }
+            });
+
+            $(document).on('click','input.copy-text',function(){
+              theButton = $(this);
+														$('input.copy-text').attr('src','images/clipboard.png');
+							              $('span.copy-animation,span.copy-animation-ps').removeClass('copy-animation copy-animation-ps');
+              try {
+                if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
+                  $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
+								} else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
+									$('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
+                } else {
+                  $('#'+ theButton.attr('rel')).addClass('copy-animation');
+                }
+                navigator.clipboard.writeText(theButton.data('clipboard-text').replace(/<[^>]*>?/gm, ''));
+																theButton.attr('src','images/clipboard_active.png');
+								              } catch(err) {
+              }
+              return false;
+            });
+
+            $(document).on('click','input.completeBox',function(){
+              theBox = $(this);
+              $('#'+ theBox.attr('rel')).addClass('strikethrough');
+              theBox.prop('disabled',true);
+              theBox.parent('li').prevAll().each(function(i,e){
+                theLI = $(this);
+                if(theLI.find('input[type=checkbox]').not(':checked')){
+                  $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
+                  theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
+                }
+              });
+            });
+
+            if(window.self !== window.top){
+															window.parent.$('iframe.stepsFrame').height((this['scrollingElement']['scrollHeight']+20) +'px');
+							            }
+          });
+        </script>
+        <link href="css/steps.css" rel="stylesheet" type="text/css" />
+      </head>
+      <body>
+        <div id="gridContainer">
+          <div class="topMargin"></div>
+          <div id="listName" class="topMargin">
+            <h1>Install and Configure nginx on Windows</h1>
+          </div>
+          <div></div>
+          <div id="content">
+          <h2>Installing and Running nginx</h2>
+
+<ol>
+	<li>Download nginx for Windows <a href="http://nginx.org/en/download.html" target="_blank">Download</a></li>
+	<li>Extract the downloaded .zip file</li>
+	<li>Rename the extracted folder nginx</li>
+	<li>Copy the extracted nginx files to the desired location, for example C:\Program Files\nginx</li>
+	<li>Open the nginx folder and double click nginx.exe to run the server</li>
+</ol>
+
+<h2>Adding PHP Support</h2>
+
+<ol>
+	<li><label for="cb_li_410392_0">Download Microsoft Visual C++</label><label for="cb_li_410392_0"><a href="https://aka.ms/vs/16/release/vc_redist.x64.exe" target="_blank">Download</a></label></li>
+	<li>Download PHP for Windows (VC15 x64 NTS)&nbsp;<a href="http://windows.php.net/download/" target="_blank">Download</a></li>
+	<li>Install Microsoft Visual C++</li>
+	<li>Extract the downloaded .zip file</li>
+	<li>Rename the extracted folder php</li>
+	<li>Copy the extracted php folder to the desired location, for example C:\Program Files\PHP</li>
+	<li>Open the php install location and right click in the white space while holding down the Shift key &gt; Open PowerShell window here</li>
+	<li>Paste the following command in the PowerShell window to start the PHP CGI process
+	<div class="codeBlock">.\php-cgi.exe -b 127.0.0.1:9123</div>
+	</li>
+	<li>Open Windows Explorer and navigate to the nginx installation directory /conf</li>
+	<li>Edit nginx.conf in a text editor</li>
+	<li>Add the following lines inside the server object
+	<p>location ~ \.php$ {<br />
+	&nbsp; &nbsp; fastcgi_pass &nbsp; 127.0.0.1:9123;<br />
+	&nbsp; &nbsp; fastcgi_index &nbsp;index.php;<br />
+	&nbsp; &nbsp; fastcgi_param &nbsp;SCRIPT_FILENAME &nbsp;$document_root$fastcgi_script_name;<br />
+	&nbsp; &nbsp; include &nbsp; &nbsp; &nbsp; &nbsp;fastcgi_params;<br />
+	}</p>
+	</li>
+	<li>Save the changes to nginx.conf</li>
+	<li>Right click the Start button &gt; Run &gt; Type taskkill /f /im &quot;nginx.exe&quot; &gt; Press Enter</li>
+	<li>Double click nginx.exe to restart the process with PHP support</li>
+</ol>
+
+<h2>Running nginx Server on Startup</h2>
+
+<p>nginx doesn&#39;t currently have the ability to run as a Windows service natively. A simple workaround is to create a scheduled task to start the nginx server on system startup</p>
+
+<ol>
+	<li>Open notepad and paste the following into a blank text file<br />
+	start &quot;&quot; /b &quot;C:\Program Files\PHP\php-cgi.exe&quot; -b 127.0.0.1:9123<br />
+	start &quot;&quot; /b &quot;C:\Program Files\nginx\nginx.exe&quot; -c &quot;C:\Program Files\nginx\conf\nginx.conf&quot;</li>
+	<li>Save the text file as startup.bat in the nginx installation directory</li>
+	<li>Click the Start button &gt; Search Task &gt; Click Task Scheduler</li>
+	<li>Right click the Task Scheduler Library folder in the top left &gt; Create Basic Task</li>
+	<li>Name the task nginx startup &gt; Click Next</li>
+	<li>Select When the computer starts &gt; Click Next</li>
+	<li>Select Start a program &gt; Click Next</li>
+	<li>Click the Browse... button and navigate to&nbsp;C:\Program Files\nginx\startup.bat</li>
+	<li>Set the Start in value to&nbsp;C:\Program Files\nginx &gt; Click Next</li>
+	<li>Click Finish</li>
+	<li>Reboot to test that nginx with PHP support starts with the system on boot</li>
+</ol>
+
+<p>Source:&nbsp;<a href="http://nginx.org/en/docs/windows.html" target="_blank">http://nginx.org/en/docs/windows.html</a></p>
+          </div>
+        </div>
+      </body>
+    </html>
+