Reference: http://www.cnblogs.com/huayangmeng/archive/2011/06/15/2081337.html
Configure nginx+php environment under windows
When I just saw the word nginx, I was curious about its pronunciation (engine x). My literal translation is "engine x". Generally, "engine x" is used to indicate performance, and "x" mostly appears to mean "xtras (extra The effect)", then the whole word means something like "extreme effect" and "extra performance". Of course, this is not here to chat, the above is a digression.
Compared with the familiar apache and IIS, nginx has the advantages of "reverse proxy" and "load balancing" as far as I understand it in a simple way. Therefore, considering that it can save resources for the Web server, it can replace apache to provide Web services. So let’s get to the point, nginx has so many advantages, how to configure nginx+php environment under windows? There are still so many reprinted articles on the Internet. Here is my configuration process to introduce:
1. The application package that needs to be prepared first.
nginx:nginx/Windows-1.0.4
php: php-5.2.16-nts-Win32-VC6-x86.zip (php under nginx runs in FastCGI mode, so we download the non-thread-safe php package that is nts)
(Also used) RunHiddenConsole: RunHiddenConsole.zip
2. Installation and configuration.
1) PHP installation and configuration.
Decompress the downloaded php package directly, and go to the wnmp directory (D:\wnmp) of drive D. Here, rename the decompressed folder to php5. Enter the folder to modify the php.ini-recommended file to php.ini, and open it with Editplus or Notepad++. turn up
extension_dir = " ./ext "
change to
extension_dir = " D:/wnmp/php5/ext "
;extension = php_mysql.dll ;extension = php_mysqli.dll
After specifying the ext path of php, just remove the corresponding ";" in front of the required expansion package. Open php_mysql.dll and php_mysqli.dll here to let php support mysql. Of course, don't forget the very important step is to copy the libmysql.dll file in the php5 directory to the C:\Windows directory. You can also specify the path in the system variable. Of course, I chose the more convenient method ^_^.
At this point, php can already support mysql.
Next we will configure php so that php can be combined with nginx. turn up
;cgi.fix_pathinfo = 1
We remove the title here.
cgi.fix_pathinfo = 1
2) Installation and configuration of nginx.
Decompress the downloaded nginx-1.0.4 package to the wnmp directory of drive D and rename it to nginx. Next, let's configure nginx so that it can work with php. Enter the nginx conf directory, open the nginx configuration file nginx.conf, and find
location / { root html; #This is the root directory of the site index index.html index.htm; }
To the root HTML; to root D: / wnmp / www;
Go down and find
# 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; #}
先将前面的“#”去掉,同样将root html;改为root D:/wnmp/www;。再把标记为红色的/scripts改为“$document_root”,这里的“$document_root”就是指前面“root”所指的站点路径,这是改完后的:
# pass the PHP scripts to FastCGI server listening on 127.0 . 0.1 : 9000 # location ~ \. php $ { root D: /wnmp/www; fastcgi_pass 127.0.0.1:9000 ; fastcgi_index index . php ; fastcgi_param SCRIPT_FILENAME $document_root $ fastcgi_script_name ; include fastcgi_params ; }
保存配置文件,就可以了。
nginx+php的环境就初步配置好了,来跑跑看。我们可以输入命令
来启动php,并手动启动nginx,当然也可以利用脚本来实现。
First, unzip the downloaded RunHiddenConsole.zip package to the nginx directory. The function of RunHiddenConsole.exe is to automatically close the script after executing the command line script, and the process opened from the script will not be closed. Then create a script, named "start_nginx.bat", we edit it in Notepad++
@echo off REM Not available under Windows REM set PHP_FCGI_CHILDREN=5 REM The maximum number of requests processed by each process, or set as a Windows environment variable set PHP_FCGI_MAX_REQUESTS = 1000 echo Starting PHP FastCGI ... RunHiddenConsole D: / wnmp / php5 / php-cgi . exe -b 127.0 . 0.1 : 9000 -c D: / wnmp / php5 / php . this echo Starting nginx ... RunHiddenConsole D: / wnmp / nginx / nginx . exe -p D: / wnmp / nginx
Create another script called stop_nginx.bat to shut down nginx
@echo off echo Stopping nginx ... taskkill / F / IM nginx . exe > no echo Stopping PHP FastCGI ... taskkill / F / IM php-cgi . exe > no exit
After it's done, it looks like this
In this way, our service script is also created. Double-click start_nginx.bat to see if the process manager has two nginx.exe processes and one php-cgi.exe process?
In this way, the nginx service is started, and php is also running in fastCGI mode.
Go to the site directory, create a new phpinfo.php file, and edit it inside
<? php phpinfo (); ?>
After saving, open the browser and enter "http://localhost/phpinfo.php", if you see
It means that the environment of nginx+php has been configured, hehe~
Nginx configuration file
#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 1024;
}
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 81;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root D:\php\pingqiujia;
#root "D:/www/project/pingqiujia/";
location / {
index index.html index.htm index.php;
#autoindex on;
}
if ($request_filename !~ (static|tmp|docment|robots\.txt|ceshi.php|index\.php.*) ) {
rewrite ^/(.*)$ /index.php?$1 last;
}
location ~ \.php(.*)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^((?U).+\.php)(/?.+)$;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
include fastcgi_params;
}
#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;
#}
# 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 ssl;
# server_name localhost;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
Quick start start_nginx.bat
@echo off
echo Starting PHP FastCGI...
D:\program\nginx-1.6.3\RunHiddenConsole.exe D:\program\php-5.6.15-nts-Win32-VC11-x64\php-cgi.exe -b 127.0.0.1:9000 -c D:\program\php-5.6.15-nts-Win32-VC11-x64\php.ini
echo Starting nginx...
D:\program\nginx-1.6.3\RunHiddenConsole.exe D:/program/nginx-1.6.3/nginx.exe -p D:/program/nginx-1.6.3
Quickly close stop_nginx.bat
@echo off
echo Stopping nginx...
taskkill /F /IM nginx.exe > nul
echo Stopping PHP FastCGI...
taskkill /F /IM php-cgi.exe > nul
exit