找回密码
 注册
首页 ≡≡网络技术≡≡ 服务器 nginx+php的windows配置

nginx+php的windows配置

灰儿 2009-5-9 09:02:40
都说nginx性能比apache还好,而且现在支持windows环境,所以拿来试试看吧,基本上都是跟着google边查边做。


1、下载

http://www.kevinworthington.com/nginx-for-windows/

我下载的稳定版,0.6.36,其中已经包括了cygwin环境。

2、安装

程序安装没有路径选项,直接默认安装在c:\nginx目录,可以选择在桌面或快速启动栏防止图标。

安装好以后,点击“Start Nginx”,根据默认的nginx.conf(位于c:\nginx\conf)配置文件,即可启动nginx支持html页面显示。

在浏览器地址栏输入http://localhost,应该可以看到测试页面,其实该页面位于c:\nginx\html目录,即web页面文件所在位置。

3、PHP配置

将php目录中的php5ts.dll(php 5.x版本,如果是php 4.x版本,则是php4ts.dll)复制到windows安装目录。

将php目录及其ext目录放到系统路径PATH中,这可能需要重新启动系统才能生效。

根据google的结果,设置php.ini中以下三个地方:

cgi.force_redirect = 0

fastcgi.impersonate = 1

cgi.rfc2616_headers = 1


4、启动php的fastcgi

打开命令行窗口,从php目录运行:

php-cgi.exe -b 127.0.0.1:9000(端口可以更换)


这个命令行窗口在正常情况下是不关闭的,可以另外打开一个命令行窗口,运行:

netstat -an


检查是否存在9000端口的监听。

5、修改nginx.conf文件
  1. #user nobody;
  2. worker_processes 1;

  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice; //nginx错误日志,可以取消注释
  5. #error_log logs/error.log info;

  6. #pid logs/nginx.pid;


  7. events {
  8. worker_connections 1024;
  9. }


  10. http {
  11. include mime.types;
  12. default_type application/octet-stream;

  13. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  14. # '"$status" $body_bytes_sent "$http_referer" '
  15. # '"$http_user_agent" "$http_x_forwarded_for"';

  16. #access_log logs/access.log main; //nginx访问日志,可以取消注释

  17. sendfile on;
  18. #tcp_nopush on;

  19. #keepalive_timeout 0;
  20. keepalive_timeout 65;

  21. #gzip on;

  22. server {
  23. listen 80; //web server服务端口
  24. server_name localhost;

  25. charset utf-8; //字符集

  26. #access_log logs/host.access.log main;

  27. location / {
  28. root /cygdrive/f/www/wwwroot; //web页面文件路径,请注意是cygwin环境的写法
  29. index index.html index.htm index.php; //加入默认php页
  30. }

  31. #error_page 404 /404.html;

  32. # redirect server error pages to the static page /50x.html
  33. #
  34. error_page 500 502 503 504 /50x.html;
  35. location = /50x.html {
  36. root html;
  37. }

  38. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  39. #
  40. #location ~ \.php$ {
  41. # proxy_pass http://127.0.0.1;
  42. #}

  43. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  44. #
  45. location ~ \.php$ {
  46. # root html;
  47. fastcgi_pass 127.0.0.1:9000; //端口要符合php的fastcgi运行端口
  48. fastcgi_index index.php;
  49. fastcgi_param SCRIPT_FILENAME f:/www/wwwroot$fastcgi_script_name; //请注意这里的路径用web页面文件的绝对路径
  50. include fastcgi_params;
  51. }

  52. # deny access to .htaccess files, if Apache's document root
  53. # concurs with nginx's one
  54. #
  55. #location ~ /\.ht {
  56. # deny all;
  57. #}
  58. }


  59. # another virtual host using mix of IP-, name-, and port-based configuration
  60. #
  61. #server {
  62. # listen 8000;
  63. # listen somename:8080;
  64. # server_name somename alias another.alias;

  65. # location / {
  66. # root html;
  67. # index index.html index.htm;
  68. # }
  69. #}


  70. # HTTPS server
  71. #
  72. #server {
  73. # listen 443;
  74. # server_name localhost;

  75. # ssl on;
  76. # ssl_certificate cert.pem;
  77. # ssl_certificate_key cert.key;

  78. # ssl_session_timeout 5m;

  79. # ssl_protocols SSLv2 SSLv3 TLSv1;
  80. # ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP;
  81. # ssl_prefer_server_ciphers on;

  82. # location / {
  83. # root html;
  84. # index index.html index.htm;
  85. # }
  86. #}

  87. }
复制代码

6、启动nginx,运行一个php页面看看吧。

然后,就可以编写一下批处理文件,加入系统计划任务,让windows启动即可运行nginx。

37 点击
您需要登录后才可以回帖 登录 | 注册
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。
学习中心
站长自定义文字内容,利用碎片时间,随时随地获取优质内容。
Q设计语言 了解更多
Q Design 提供商家设计所需的指导与资源,帮商家快速完成产品设计、降低生产成本。