当前位置:Gxlcms > PHP教程 > nginx环境搭建(windows)

nginx环境搭建(windows)

时间:2021-07-01 10:21:17 帮助过:14人阅读

安装nginx

下载nginx(官网)
本次下载的是:nginx/Windows-1.10.1(Mainline version)
然后将zip包解压,放到指定目录。
cmd查看nginx -h 命令

  1. <code>D:\nginx-<span>1.11</span><span>.1</span>>nginx.exe -h
  2. nginx version: nginx/<span>1.11</span><span>.1</span>
  3. Usage: nginx [-?hvVtTq] [-s <span>signal</span>] [-c filename] [-p prefix] [-g directives]
  4. Options:
  5. -?,-h : this help
  6. -v : show version <span>and</span><span>exit</span>
  7. -V : show version <span>and</span> configure options <span>then</span><span>exit</span>
  8. -t : test <span>configuration</span><span>and</span><span>exit</span>
  9. -T : test <span>configuration</span>, dump it <span>and</span><span>exit</span>
  10. -q : suppress non-error messages during <span>configuration</span> testing
  11. -s <span>signal</span> : send <span>signal</span><span>to</span> a master <span>process</span>: stop, quit, reopen, reload
  12. -p prefix : set prefix path (<span>default</span>: NONE)
  13. -c filename : set <span>configuration</span><span>file</span> (<span>default</span>: conf/nginx.conf)
  14. -g directives : set global directives <span>out</span><span>of</span><span>configuration</span><span>file</span></code>

官网文档命令说明(链接):

  1. <code>nginx/Windows runs <span>as</span><span>a</span> standard console application (<span>not</span><span>a</span> service), <span>and</span><span>it</span> can be managed <span>using</span><span>the</span> following commands:
  2. nginx -s stop fast shutdown
  3. nginx -s quit graceful shutdown
  4. nginx -s reload changing configuration, starting <span>new</span> worker processes <span>with</span><span>a</span><span>new</span> configuration, graceful shutdown <span>of</span> old worker processes
  5. nginx -s reopen re-opening <span>log</span><span>files</span></code>

启动nginx:D:\nginx-1.11.1>start nginx.exe
然后打开浏览器输入localhost,可以看到如下:
 nginx环境搭建(windows)
至此,nginx在windows上面就安装完毕了。

配置PHP的fast-cgi

官方教程(链接)
下载RunHiddenConsole,并放置在指定目录,例如c:\bin。
建立bat文件:start-php-fcgi.bat。文件内容如下(php-cgi.exe目录需配置):
@ECHO OFF
ECHO Starting PHP FastCGI...
set PATH=C:\PHP;%PATH%
c:\bin\RunHiddenConsole.exe C:\PHP\php-cgi.exe -b 127.0.0.1:9123

启动start-php-fcgi.bat文件。
配置nginx文件:nginx.conf。
修改server配置:

  1. <code><span>server</span> {
  2. listen <span>80</span>;
  3. server_name localhost;
  4. root e:;
  5. <span>#charset koi8-r;</span><span>#access_log logs/host.access.log main;</span> location / {
  6. <span>#root E:;</span><span>index</span><span>index</span>.html <span>index</span>.htm <span>index</span>.php;
  7. }
  8. <span>#error_page 404 /404.html;</span><span># redirect server error pages to the static page /50x.html</span><span>#</span>
  9. error_page <span>500</span><span>502</span><span>503</span><span>504</span> /<span>50</span>x.html;
  10. location = /<span>50</span>x.html {
  11. root html;
  12. }
  13. <span># proxy the PHP scripts to Apache listening on 127.0.0.1:80</span><span>#</span><span>#location ~ \.php$ {</span><span># proxy_pass http://127.0.0.1;</span><span>#}</span><span># pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000</span><span>#</span>
  14. location ~ \.php$ {
  15. <span>#root E:;</span>
  16. fastcgi_pass <span>127.0</span><span>.0</span><span>.1</span>:<span>9123</span>;
  17. fastcgi_index <span>index</span>.php;
  18. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<span>#/scripts$fastcgi_script_name;</span>
  19. include fastcgi_params;
  20. }
  21. <span># deny access to .htaccess files, if Apache's document root</span><span># concurs with nginx's one</span><span>#</span><span>#location ~ /\.ht {</span><span># deny all;</span><span>#}</span>
  22. }</code>

在root目录建立index.php

  1. <code><span>echo</span><span>"it works"</span>;</code>

然后cmd重启nginx。
浏览器里面打开localhost,看到:
 nginx环境搭建(windows)

至此nginx+php配置完毕。

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了 nginx环境搭建(windows),包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行