初探wnmp php

wnmp是windows下,Nginx、MySQL、PHP的环境集成包。新手用该集成包学习PHP,搭建自己的本地服务器十分便利。原理性的东西我还需要进一步学习,现在先简单看一下如何完成初始的环境构建。
首先进行本地服务器地址路径设置:
打开安装目录下的conf文件,在其中找到nginx.conf。初始配置文件如下:

worker_processes  1;

error_log  logs/error.log;
pid        logs/nginx.pid;

events {
    # Max value 16384
    worker_connections  8192;
    # Accept multiple connections
    multi_accept on;
}

# Settings that affect all server blocks
http {
    include php_processes.conf;
    include       mime.types;
    default_type  application/octet-stream;

    access_log  logs/access.log;

    sendfile on;
    
    keepalive_timeout  65;
    ssl_session_timeout 10m;
    ssl_protocols TLSv1.2 TLSv1.1 TLSv1 SSLv3;
    ssl_ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS; 
    ssl_prefer_server_ciphers on;
    gzip  on;
    # http server

# Begin HTTP Server
server {
    listen 80; # IPv4
    server_name localhost;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;

    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }
        
    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {

        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        ## Static files
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }

        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        } # / location

} 
# End HTTP Server

# Begin HTTPS Server
server {
    listen 443 http2 ssl;
    server_name localhost;
    ssl_certificate      cert.pem;
    ssl_certificate_key  key.pem;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;

    ## Parametrization using hostname of access and log filenames.
    access_log logs/localhost_access.log;
    error_log logs/localhost_error.log;

    ## Root and index files.
    root html;
    index  index.php index.html index.htm;

    ## If no favicon exists return a 204 (no content error).
    location = /favicon.ico {
        try_files $uri =204;
        log_not_found off;
        access_log off;
    }

    ## Don't log robots.txt requests.
    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }
    ## Try the requested URI as files before handling it to PHP.
    location / {

        ## Regular PHP processing.
        location ~ \.php$ {
            try_files  $uri =404;
            fastcgi_pass   php_processes;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        ## Static files are served directly.
        location ~* \.(?:css|gif|htc|ico|js|jpe?g|png|swf)$ {
            expires max;
            log_not_found off;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
            ## Set the OS file cache.
            open_file_cache max=1000 inactive=120s;
            open_file_cache_valid 45s;
            open_file_cache_min_uses 2;
            open_file_cache_errors off;
        }

        ## Keep a tab on the 'big' static files.
        location ~* ^.+\.(?:ogg|pdf|pptx?)$ {
            expires 30d;
            ## No need to bleed constant updates. Send the all shebang in one
            ## fell swoop.
            tcp_nodelay off;
        }
        } # / location
} # End HTTPS Server
}

改变http和https中的root下的路径为你所需要搭建本地服务器的路径,默认为html即可,其它内容还得继续研究,先跑起来再说~

此时,打开wnmp,start all之后,在浏览器输入localhost,看到这个页面,就代表已经安装成功:

然后,自己尝试搭建第一个网页:

1、简单描述下web 服务器、PHP、数据库、浏览器是如何实现动态网站的?

要了解动态网站,首先我们得知道一个用户获取静态网页的过程:

  • 首先用户在浏览器输入URL后,通过DNS来获取IP地址以找到相对应服务器。
  • 服务器根据用户的需求,即URL地址上所表达的东西,返回给浏览器一个静态的HTML文件。
  • 最后浏览器对该HTML文件进行渲染展现给用户。

如果网页是一成不变的还好,但是涉及到表单提交时,静态网站就远不能满足用户的需求了:


在静态网页,用户表单填写无法与服务器进行交互,只能将数据填写完成之后,以邮件发送的形式将数据提交,且无法检查自己填写的信息,这么麻烦的操作催生了动态网页的形成。

  • 首先用户按照静态页面的方式获取了一个页面;
  • 当用户在该静态页面上发送请求时,向服务器提交了一个php脚本的地址;
  • 服务器通过php对用户的需求进行处理:可以发送邮件,也可以通过数据库(php一般对应的MySQL)增删改查来存储数据;
  • 服务器将运行过php转换为html文件,并返还给浏览器;
  • 浏览器对html文件进行渲染,呈现在用户面前。

2、常见的web服务器有哪些?

最常见的WEB服务器是:Apache、Nginx、IIS;
此外还有:Tomcat和Zeus。

3、打开浏览器,在地址栏输入 http://jirengu.com 页面展现了饥人谷官网的信息,整个过程发生了什么?(饥人谷官网后台语言 php,web服务器 nginx,数据库 mysql)

  • 首先在浏览器输入了URL地址(http://jirengu.com](http://jirengu.com/)
  • 互联网通过DNS将URL翻译成IP地址(如果先前访问过该网站,通过浏览器->操作系统->路由器->运营商->根,层层寻找DNS缓存,一定会得到!);
  • 若用户以前登录过饥人谷官网,随着URL地址传过来的还有一个cookie。
  • 此饥人谷的服务器nginx得到响应,根据用户的需求,通过PHP进行处理,如果涉及到用户登录以及数据请求或提交,还将与数据库MySQL进行交互,服务器将返回一个静态的html文档。
  • 通过TCP/IP协议三次握手,确定网络正常,将静态html文档送至客户端(浏览器)。
  • 浏览器对html进行渲染,将饥人谷官网呈现给用户。
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,323评论 19 139
  • 第一章 Nginx简介 Nginx是什么 没有听过Nginx?那么一定听过它的“同行”Apache吧!Ngi...
    JokerW阅读 32,861评论 24 1,002
  • 每逢春节,一票难求,很多老哥都会选择自驾回乡过年。小编在这里提前和大家分享一些冬季长途驾车的安全小常识。 1.防范...
    五哥说车阅读 2,985评论 0 0
  • 周五参加了头马资深资深大咖同时也是TDB创始人郭老师进行的一场面试培训,干货满满、收获很多,与大家一起分享希望共同...
    batheny阅读 8,173评论 2 3