nginx环境搭建(windows),nginx搭建


安装nginx

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

D:\nginx-1.11.1>nginx.exe -h
nginx version: nginx/1.11.1
Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]

Options:
  -?,-h         : this help
  -v            : show version and exit
  -V            : show version and configure options then exit
  -t            : test configuration and exit
  -T            : test configuration, dump it and exit
  -q            : suppress non-error messages during configuration testing
  -s signal     : send signal to a master process: stop, quit, reopen, reload
  -p prefix     : set prefix path (default: NONE)
  -c filename   : set configuration file (default: conf/nginx.conf)
  -g directives : set global directives out of configuration file

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

nginx/Windows runs as a standard console application (not a service), and it can be managed using the following commands:

nginx -s stop   fast shutdown
nginx -s quit   graceful shutdown
nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes
nginx -s reopen re-opening log files

启动nginx:D:\nginx-1.11.1>start nginx.exe
然后打开浏览器输入localhost,可以看到如下:

至此,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配置:

    server {
        listen       80;
        server_name  localhost;
        root e:;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            #root   E:;
            index  index.html index.htm index.php;
        }

        #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          E:;
            fastcgi_pass   127.0.0.1:9123;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;#/scripts$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;
        #}
    }

在root目录建立index.php

echo "it works";

然后cmd重启nginx。
浏览器里面打开localhost,看到:

至此nginx+php配置完毕。

相关内容

    暂无相关文章