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 <?php
2     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  

重新启动服务器,访问web服务发现无法浏览啦!登陆服务器之后进到nginx使用./nginx -s reload重新读取配置文件,发现报nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)错误,进到logs文件发现的确没有nginx.pid文件

[[email protected] sbin]# ./nginx -s reload

nginx: [error] open() "/usr/local/nginx/logs/nginx.pid" failed (2: No such file or directory)

解决方法:

[[email protected] nginx]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

使用nginx -c的参数指定nginx.conf文件的位置

[[email protected] nginx]# cd logs/

[[email protected] 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  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

时间: 2024-08-18 22:59:10

Win7下配置nginx和php5的相关文章

windows下配置nginx+php环境

windows下配置nginx+php环境 刚看到nginx这个词,我很好奇它的读法(engine x),我的直译是“引擎x”,一般引“擎代”表了性能,而“x”大多出现是表示“xtras(额外的效果)”,那么整个词的意思就是类似“极致效果”,“额外性能”.当然这里不是要来唠嗑,以上是题外话. nginx相较于我们熟悉的apache.IIS的优势,就我浅入浅出的了解,在于“反向代理”和“负载均衡”.因此考虑到能够为Web服务器节省资源,它可以代替apache来提供Web服务.那么上正题了,ngin

windows 下配置 Nginx 常见问题(转)

windows 下配置 Nginx 常见问题 因为最近的项目需要用到负载均衡,不用考虑,当然用大名鼎鼎的Nginx啦.至于Nginx的介绍,这里就不多说了,直接进入主题如何在Windows下配置. 我的系统是win7旗舰版的,到官网下载最新版本 nginx/Windows-1.7.9解压到英文目录下(我刚开始是放到中文目录下的,启动时会有问题,下面常见错误里会讲到). 一.  Nginx配置 找到 conf 目录里的 nginx.conf 文件,配置Nginx #user nobody; #指定

CentOS 7 下配置 Nginx + PHP7.1 + MariaDB 以及 Laravel 框架

html { } .CodeMirror { height: auto } .CodeMirror-scroll { } .CodeMirror-lines { padding: 4px 0px } .CodeMirror pre { } .CodeMirror-scrollbar-filler,.CodeMirror-gutter-filler { background-color: white } .CodeMirror-gutters { border-right-width: 1px;

Ubuntu 16.04下配置nginx与nodejs以及服务的部署

title: Ubuntu 16.04下配置nginx与nodejs以及服务的部署 date: 2019-05-05 22:45:49 tags: Linux --- 第一步:安装nginx sudo apt-get update sudo apt-get install nginx 如果遇到依赖问题,尝试执行sudo apt-get -f install命令 第二步:配置nginx 首先备份原先的配置文件:sudo cp /etc/nginx/sites-available/default /

在CentOS/Windows下配置Nginx(以及踩坑)

在CentOS/Windows下配置Nginx(以及踩坑) 1. 序言 因为这类文章网上比较多,实际操作起来也大同小异,所以我并不会着重于详细配置方面,而是将我配置时踩的坑写出来. 2. CentOS 2.1 第一步下载nginx包 我选择将包放在/usr/local下 cd /usr/local wget (nginx下载目录网址) 这里的下载目录可以根据需要选择版本从而决定 请点击nginx下载查看目录 2.2 安装nginx所需环境 yum?install?gcc-c++ yum?inst

win7下搭建nginx+php的开发环境(转)

在win7下用的是IIS做web服务器,但近来因项目需求的原因,需要在服务器遇到404错误的时候自动做转向(不是在客户端的跳转,而是在服务器收到客户端请求去某目录下读取文件返回时,如果发现目录或目录下文件不存在,自动转到另一个服务器去取),用IIS发现很难做到这点,于是决定搭建nginx的开发环境,通过配置实现这一点. 首先,google nginx和php,分别到他们的官网把最新版本的下载回来,我当时下的PHP是5.4.3的版本,nginx是1.5.2,我把他们都放在D盘下一个叫webserv

在linux下配置nginx+java+php的环境

Apache对Java的支持很灵活,它们的结合度也很高,例如Apache+Tomcat和Apache+resin等都可以实现对Java应用 的支持.Apache一般采用一个内置模块来和Java应用服务器打交道.与Apache相比,Nginx在配合Java应用服务器方面,耦合度很低,它 只能通过自身的反向代理功能来实现与Java应用服务器的支持.但这恰恰是Nginx的一个优点,耦合度的降低,可以使Nginx与Java服务器的相互 影响降到最低. 接下来通过Nginx+Tomcat的实例来讲解Ngi

Windows下配置nginx+php(wnmp)

第一部分:准备工作.(系统:Windows 8.1) 1.首先是下载软件. NGINX-1.3.8官网下载:http://nginx.org/en/download.html PHP5.4.8版本下载地址:http://windows.php.net/download/ Mysql5.5.28版本下载地址:http://www.mysql.com/downloads/mysql/ 2.安装mysql软件. 3.解压NGINX和PHP到你自己安装位置.这里我在C盘新建一个文件夹:wnmp(wind

阿里云服务器下配置Nginx+PHP+Mysql+webbench(压力测试)+iftop(监控流量)

注意:在阿里云服务器下不用配置iptables 1.关闭SELINUX vi /etc/selinux/config #SELINUX=enforcing #注释掉 #SELINUXTYPE=targeted #注释掉 SELINUX=disabled #增加 :wq #保存退出 shutdown -r now #重启系统 2.使用yum安装wget yum install wget #安装下载工具 wget http://www.atomicorp.com/installers/atomic