您現(xiàn)在的位置:首頁(yè) >關(guān)于我們 >行業(yè)新聞 >Windows下搭建Nginx服務(wù)器步驟

Windows下搭建Nginx服務(wù)器步驟

時(shí)間:2011年6月10日

  1、準(zhǔn)備的文件:

  Nginx 下載地址:http://soft.qudong.com/down/26155.html

  PHP 下載地址:http://soft.qudong.com/down/26156.html

  MySQL 下載地址:http://soft.qudong.com/down/26154.html

  2、nginx需要的是cgi方式的php,所以如下幾個(gè)地方是重點(diǎn),否則nginx無(wú)法打開php文件 :

  enable_dl = On

  cgi.force_redirect = 0

  cgi.fix_pathinfo=1

  fastcgi.impersonate = 1

  cgi.rfc2616_headers = 1

  3、啟動(dòng)Nginx和PHP:

  啟動(dòng)Nginx很簡(jiǎn)單,使用nginx目錄下面的nginx.exe雙擊即可 .可是php的啟動(dòng)因?yàn)橐褂胏gi方式,所以有些特殊。我參照網(wǎng)上的方法下載了RunHiddenConsole.exe ,使用該工具用其執(zhí)行的cmd窗口會(huì)自動(dòng)關(guān)閉,否則你看一個(gè)CMD窗口一直在那晃來(lái)晃去,頭會(huì)暈的。

  創(chuàng)建start_php.bat,來(lái)啟動(dòng)php,文件內(nèi)容如下:

以下是代碼片段:
    @echo off
  echo Starting PHP FastCGI…
  RunHiddenConsole.exe d:\php\php-cgi.exe -b 127.0.0.1:9000 -c d:\php\php.ini

  創(chuàng)建stop_nginx.bat,來(lái)關(guān)閉php和nginx進(jìn)程,文件內(nèi)容如下:

以下是代碼片段:
    @echo off
  echo Stopping nginx…
  taskkill /F /IM nginx.exe > nul
  echo Stopping PHP FastCGI…
  taskkill /F /IM php-cgi.exe > nul
  exit

  4、nginx配置文件:(D:\nginx\conf\nginx.conf)

以下是代碼片段:
    #user nobody;
  worker_processes 1 ;
  error_log logs/error.log;
  #error_log logs/error.log notice;
  #error_log logs/error.log info;
  #pid logs/nginx.pid;
  events {
  worker_connections 64 ;
  }
  http {
  include mime.types;
  default_type application/octet-stream;
  #log_format main '$remote_addr - $remote_user [ $time_local] "$request" '
  # '$status $body_bytes_sent "$http_referer" '
  # '"$http_user_agent" "$http_x_forwarded_for" ';
  #access_log logs/access.log main;
  sendfile on;
  #tcp_nopush on;
  #keepalive_timeout 0 ;
  keepalive_timeout 65 ;
  #gzip on;
  server {
  listen 80 ;
  server_name localhost;
  charset gbk;
  #access_log logs/host.access.log main;
  location / {
  root e:\www;
  index index.html index.htm index.php;
  autoindex on;
  }
  #error_page 404 /404 .html;
  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
  root html;
  }
  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  # proxy_pass http://127.0.0.1;
  #}
  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #
  #location ~ \.php$ {
  # root html;
  # fastcgi_pass 127.0.0.1:9000 ;
  # fastcgi_index index.php;
  # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  # include fastcgi_params;
  #}
  location ~ \.php$ {
  fastcgi_pass 127.0.0.1:9000 ;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME e:\www$fastcgi_script_name;
  include fastcgi_params;
  }
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  # deny all;
  #}
  }
  # another virtual host using mix of IP-, name-, and port-based configuration
  #
  #server {
  # listen 8000 ;
  # listen somename:8080 ;
  # server_name somename alias another.alias;
  # location / {
  # root html;
  # index index.html index.htm;
  # }
  #}
  # HTTPS server
  #
  #server {
  # listen 443 ;
  # server_name localhost;
  # ssl on;
  # ssl_certificate cert.pem;
  # ssl_certificate_key cert.key;
  # ssl_session_timeout 5m;
  # ssl_protocols SSLv2 SSLv3 TLSv1;
  # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  # ssl_prefer_server_ciphers on;
  # location / {
  # root html;
  # index index.html index.htm;
  # }
  #}
  }

  檢測(cè)NginX服務(wù)器是否啟動(dòng)好可以 通過(guò) 查看 nginx\logs\error.log 文件信息知道。本文由服務(wù)器租用——海騰數(shù)據(jù)(http://cryokeys.com)提供。

Copyright© 2004-2020 河南海騰電子技術(shù)有限公司 版權(quán)所有   經(jīng)營(yíng)性ICP/ISP證 備案號(hào):B1-20180452   豫公網(wǎng)安備 41019702002018號(hào)    電子營(yíng)業(yè)執(zhí)照