Win7下配置nginx和php5

时间:2023-02-21 09:11:36

本文链接: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 <?php
2 phpinfo();
3 ?>

六、运行D:\nginx\php-cgi.cmd和D:\nginx\nginx.exe,然后打开:http://localhost/index.php,有没有看到熟悉的phpinfo页面!

七、nginx基本命令:

重新加载nginx 配置

D:\nginx-1.3.>nginx -s reload  

在浏览中键入:http://127.0.0.1

看到 test is ok !说明工作正常

停止nginx:

D:\nginx-1.3.>nginx -s stop  

显示nginx 帮助

 D:\nginx-1.3.>nginx -h  
重新启动服务器,访问web服务发现无法浏览啦!登陆服务器之后进到nginx使用./nginx -s reload重新读取配置文件,发现报nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)错误,进到logs文件发现的确没有nginx.pid文件
 
[root@localhost sbin]# ./nginx -s reload
nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)
 
解决方法:
[root@localhost nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
 
使用nginx -c的参数指定nginx.conf文件的位置
 
[root@localhost nginx]# cd logs/
[root@localhost logs]# ll
总用量 12
-rw-r--r-- 1 root root 1246 12月  9 18:10 access.log
-rw-r--r-- 1 root root  516 12月 10 15:39 error.log
-rw-r--r-- 1 root root    5 12月 10 15:38 nginx.pid
 
看nginx.pid文件已经有了。
 
在windows中配置vhost/*.conf出错,导致nginx.pid消失,在nginx.conf中将 # include vhost/*.conf;注释 然后重新nginx -s reload就好了
 
nginx.conf配置内容
#user  nobody;
worker_processes ; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections ;
} 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 ;
keepalive_timeout ; #gzip on; #server {
#listen ;
#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 /.html; # redirect server error pages to the static page /50x.html
#
# error_page /50x.html;
#location = /50x.html {
# root html;
#} # proxy the PHP scripts to Apache listening on 127.0.0.1:
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:;
# 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 ;
# listen somename:;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen ;
# 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 *:; #换成你的IP地址
client_max_body_size 100M;
server_name www.yii2.com; #换成你的域名
charset utf-; location / {
root d:/nginx-1.3./html/yii2;
index index.html index.htm index.php;
} #打开目录浏览,这样当没有找到index文件,就也已浏览目录中的文件
autoindex on; if (-d $request_filename) {
rewrite ^/(.*)([^/])$ http://$host/$1$2/ permanent;
} error_page /.html;
location = /40x.html {
root d:/nginx-1.3./html/yii2; #你的站点路径
charset on;
} # redirect server error pages to the static page /50x.html
#
error_page /50x.html;
location = /50x.html {
root d:/nginx-1.3./html/yii2; #你的站点路径
charset on;
} #将客户端的请求转交给fastcgi
location ~ .*\.(php|php5|php4|shtml|xhtml|phtml)?$ {
root d:/nginx-1.3./html/yii2; #你的站点路径
fastcgi_pass 127.0.0.1:;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME d:/nginx-1.3./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的更多相关文章

  1. windows 下配置 Nginx 常见问题&lpar;转&rpar;

    windows 下配置 Nginx 常见问题 因为最近的项目需要用到负载均衡,不用考虑,当然用大名鼎鼎的Nginx啦.至于Nginx的介绍,这里就不多说了,直接进入主题如何在Windows下配置. 我 ...

  2. Windows下配置Nginx

    一.今天是2017年1月18日.揣着一种也许叫做冲动的心情,决定以后每天都记录和回顾新涉及的技术,巩固已学到的知识,坚持. 二.回归到今天的技术主题,因为之前对于[反向代理]这种技术充满了好奇,借此机 ...

  3. 【高可用HA】Nginx &lpar;1&rpar; —— Mac下配置Nginx Http负载均衡&lpar;Load Balancer&rpar;之101实例

    [高可用HA]Nginx (1) -- Mac下配置Nginx Http负载均衡(Load Balancer)之101实例 nginx版本: nginx-1.9.8 参考来源: nginx.org [ ...

  4. 在CentOS&sol;Windows下配置Nginx(以及踩坑)

    在CentOS/Windows下配置Nginx(以及踩坑) 1. 序言 因为这类文章网上比较多,实际操作起来也大同小异,所以我并不会着重于详细配置方面,而是将我配置时踩的坑写出来. 2. CentOS ...

  5. CentOS 7 下配置 Nginx &plus; PHP7&period;1 &plus; MariaDB 以及 Laravel 框架 2018&period;3&period;11

    CentOS 7 下配置 Nginx + PHP7.1 + MariaDB 以及 Laravel 框架 阿里云服务器的选择 当然是选择学生优惠啦.这里阿里云还提供了轻量级服务器这个选项,可以预装 LA ...

  6. CentOS 7 下配置 Nginx &plus; PHP7&period;1 &plus; MariaDB 以及 Laravel 框架

    <!doctype html> CentOS 7 下配置 Nginx + PHP7.1 + MariaDB 以及 Laravel 框架.mdhtml {overflow-x: initia ...

  7. win7下搭建nginx&plus;php的开发环境

    本来在win7下用的是IIS做web服务器,但近来因项目需求的原因,需要在服务器遇到404错误的时候自动做转向(不是在客户端的跳转,而是在服务器收到客户端请求去某目录下读取文件返回时,如果发现目录或目 ...

  8. win7下搭建nginx&plus;php的开发环境(转)

    在win7下用的是IIS做web服务器,但近来因项目需求的原因,需要在服务器遇到404错误的时候自动做转向(不是在客户端的跳转,而是在服务器收到客户端请求去某目录下读取文件返回时,如果发现目录或目录下 ...

  9. Windows下配置nginx&plus;php&lpar;wnmp&rpar;

      第一部分:准备工作.(系统:Windows 8.1) 1.首先是下载软件. NGINX-1.3.8官网下载:http://nginx.org/en/download.html PHP5.4.8版本 ...

随机推荐

  1. 死去活来,而不变质:Domain Model(领域模型) 和 EntityFramework 如何正确进行对象关系映射?

    写在前面 阅读目录: 设计误区 数据库已死 枚举映射 关联映射 后记 在上一篇<一缕阳光:DDD(领域驱动设计)应对具体业务场景,如何聚焦 Domain Model(领域模型)?>博文中, ...

  2. LCA &plus; 树状数组 &plus; 树上RMQ

    题目链接:http://poj.org/problem?id=2763 思路:首先求出树上dfs序列,并且标记树上每个节点开始遍历以及最后回溯遍历到的时间戳,由于需要修改树上的某两个节点之间的权值,如 ...

  3. asp&period;net开发中常见公共捕获异常方式总结&lpar;附源码&rpar;

    本文实例总结了asp.net开发中常见公共捕获异常方式.分享给大家供大家参考,具体如下: 前言:在实际开发过程中,对于一个应用系统来说,应该有自己的一套成熟的异常处理框架,这样当异常发生时,也能得到统 ...

  4. javascript&comma;jQuery&comma;trim&lpar;&rpar;

    JavaScript trim() Syntax string.trim() The trim() method removes whitespace from both sides of a str ...

  5. 低版本Xcode 出现could not find developer disk image问题

    解决Xcode在ipad/iphone9.2系统真机测试时出现could not find developer disk image问题,只要拷贝这个文件(链接: http://pan.baidu.c ...

  6. js 定义函数的几种方法 以及如何调用

    /*1.方法调用模式: 先定义一个对象,然后在对象的属性中定义方法,通过myobject.property来执行方法,this即指当前的myobject 对象.*/ var car = { carId ...

  7. linux(九)之网络基础

    一.ping命令 1.1.作用 用于检测主机.执行ping指令会使用ICMP传输协议,发出要求回应的信息,若远端主机的网络功能没有问题,就会回应该信息,因而得知该主机运作正常. 1.2.命令说明 pi ...

  8. 201521123004《Java程序设计》第8周学习总结

    1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结集合与泛型相关内容. 1.2 选做:收集你认为有用的代码片段 答:主要以泛型为主 //简单的泛型类的定义,T为类型参数 public ...

  9. Mybatis插入MySQL数据库中文乱码

    Mybatis插入MySQL数据库中文乱码 在dataSource.properties配置文件中设置useUnicode=true&characterEncoding=utf-8编码即可. ...

  10. &lbrack;问题解决&rsqb;eclipse&period;ini 文件配置jdk版本

    想要多个JDK 和 多个eclipse在一台电脑上同时运行无需配置环境变量,只需修改eclipse.ini文件即可启动eclipse. -vm D:\javaSE1.\jdk1.\bin\javaw. ...