Nginx安装

环境:VC2008
版本:Nginx1.9
系统:Server 2003 SP2  (SP1系统,需要安装SP2补丁)
PS:不安装补丁会报>> 无法定位程序输入点 DecodePointer 于 动态链接库 KERNEL32.dll上 错误。
 
Nginx常用配置(nginx.conf)注释: 
http {  
  server {  
    #1.侦听80端口   
    listen  80;   
    location / {  
        # 2. 默认主页目录在nginx安装目录的html子目录。  
        root   html;  
        index  index.html index.htm;  
        # 3. 根据需要选择,没有索引页时,罗列文件和子目录,不添加语句会抛出Nginx403错误
        autoindex on;  
        autoindex_exact_size on;  
        autoindex_localtime on;  
    }  
    # 4.指定虚拟目录  
    location /tshirt {  
    alias D:\programs\Apache2\htdocs\tshirt;  
    index index.html index.htm;  
    }  
  }  
  # 5.虚拟主机www.emb.info配置  
  server {  
    listen          80;  
    server_name     www.emb.info;  
    access_log emb.info/logs/access.log;  
    location / {  
      index index.html;  
      root  emb.info/htdocs;  
    }  
  }  
} 
 
支持PHP:
1.修改PHP.inf配置文件:
error_reporting = E_ALL     
display_errors = On            
extension_dir = "C:\php\ext"    #这里ext为扩展模块的目录
; 动态扩展,可以根据需要去掉 extension 前面的注释 ; 
; 加载 PDO, MySQL
extension=php_pdo.dll
extension=php_pdo_mysql.dll
; CGI 设置
cgi.force_redirect = 1
cgi.fix_pathinfo = 1                  #默认应该是0,不修改会造成无法找到需要处理的php脚本
cgi.rfc2616_headers = 1

PHP 加载扩展需要注意依赖性,比如 php_exif.dll 需要 php_mbstring.dll,你必须要把 php_mbstring.dll 放在 php_exif.dll 前面才能加载成功。

PS:PHP加载模块说明:

错误:开Apche提示找不到:libmysql.dll 错误。

原因:因为php\ext 目录下面没有libmysql,这是php_mysql.dll模块的依赖模块,必须在php_mysql.dll之前导入它才行。

解决:在php主目录下面找到了libmysql.dll(没有就需要去下载),拷贝至ext目录下面,然后要将它加入到php.inf中,找到“ extension=php_mysql ”在它之前添加: extension=libmysql.dll
 

2.配置PHP FastCGI

Nginx 需要和 FastCGI Server 配合才能处理请求:

命令行运行:c:/php/php-cgi.exe -b 127.0.0.1:9000 -c c:/php/php.ini   #启动FastCGI

PS:如果上面没有配置好模块路径(etx路径),会报找不到模块错误

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ \.php$ {
root    d:/public_html;     # 这里修改网站目录为你需要的目录,如:d:/Apache22/www
include php.conf;
}

 PS:php.conf为自己创建的配置文件,之所以要创建一个独立的 php.conf 保存配置为了精简 nginx.conf,当在 nginx 中配置多个虚拟主机时,每个虚拟主机都需要配置 php,那么主配置文件就会变得重复、臃肿。

需要修改一下 *\nginx\conf\fastcgi_params文件,加入一行:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;

php.conf如下:

# 连接到本机 9000 端口,这里的端口是指 PHP FastCGI Server 开启的端口,
# 请与 php-cgi.exe 开启的端口保持一致
# 当 Nginx 收到 php 文件的请求时,会自动转发到 PHP FastCGI Server
fastcgi_pass    127.0.0.1:9000;
fastcgi_index   index.php;
include     fastcgi_params;

posted on 2015-08-27 19:54  下河坝  阅读(203)  评论(0编辑  收藏  举报

导航