首页 > 代码库 > Win7下配置nginx和php5
Win7下配置nginx和php5
本文链接:http://www.cnblogs.com/cnscoo/archive/2012/09/03/2668577.html
一、准备工作:
OS:Windows7 SP1
Nginx: nginx-1.3.5
php:php-5.4.6
二、解压php-5.4.6-Win32-VC9-x86.zip到D:\php,将其中的php.ini-production改成php.ini。
三、解压nginx-1.3.5.zip到D:\nginx,编辑D:\nginx\conf\nginx.conf文件:
location / {
root html;
index index.html index.htm index.php; #添加PHP首页
}
#取消以下注释并修改:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# html表示网站目录,须和root中的保持一致
fastcgi_param SCRIPT_FILENAME html$fastcgi_script_name;
include fastcgi_params;
}
四、在D:\nginx中添加php-cgi.cmd文件并写入内容:
"D:\php\php-cgi.exe" -b 127.0.0.1:9000 -c "D:\php\php.ini"
五、在D:\nginx\html文件夹中添加phpinfo文件index.php并写入内容:
1 <?php2 phpinfo();3 ?>
六、运行D:\nginx\php-cgi.cmd和D:\nginx\nginx.exe,然后打开:http://localhost/index.php,有没有看到熟悉的phpinfo页面!
七、nginx基本命令:
重新加载nginx 配置
D:\nginx-1.3.5>nginx -s reload
在浏览中键入:http://127.0.0.1
看到 test is ok !说明工作正常
停止nginx:
D:\nginx-1.3.5>nginx -s stop
显示nginx 帮助
D:\nginx-1.3.5>nginx -h
#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 80; #server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; #location / { # root html; # 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 html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME html$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 HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} include vhost/*.conf;}
vhost/abc.com.conf配置内容
server { listen *:80; #换成你的IP地址 client_max_body_size 100M; server_name www.yii2.com; #换成你的域名 charset utf-8; location / { root d:/nginx-1.3.5/html/yii2; index index.html index.htm index.php; } #打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件 autoindex on; if (-d $request_filename) { rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent; } error_page 404 /404.html; location = /40x.html { root d:/nginx-1.3.5/html/yii2; #你的站点路径 charset on; } # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root d:/nginx-1.3.5/html/yii2; #你的站点路径 charset on; } #将客户端的请求转交给fastcgi location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ { root d:/nginx-1.3.5/html/yii2; #你的站点路径 fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME d:/nginx-1.3.5/html/yii2$fastcgi_script_name; include fastcgi_params; } #网站的图片较多,更改较少,将它们在浏览器本地缓存15天 location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 15d; } #网站会加载很多JS、CSS,将它们在浏览器本地缓存1天 location ~ .*\.(js|css)?$ { expires 1d; } location /(WEB-INF)/ { deny all; }}
参考
http://blog.csdn.net/shoyer/article/details/8182050
http://www.cnblogs.com/cnscoo/archive/2012/09/03/2668577.html
http://www.ithov.com/linux/130990.shtml
Win7下配置nginx和php5