• centos 配置php-fpm和nginx的通信


    <span style="font-size:18px;">下面是nginx的默认配置文件:
     
    server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.access.log  main;
    
            location / {
                root   /usr/share/nginx/html;
                index  index.html index.htm;
            }
    
            #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;
            #}
        } </span>
    

    一个location匹配一个(一种)url。

    匹配到相应的url就转到相应的location中,然后进行处理请求。

    默认的root是/usr/share/nginx/html。也就是会转到相应的文件夹下进行处理请求。

    可是匹配到有php的文件就没有办法进行解析。

    这里用到了php-fpm  也就是fastcgi在php下的一个类库。

    当匹配到有.php结尾的请求的时候,就将该请求转到fastcgi进行处理。


    关于server_name 还纠结了好久,当我在同一操作系统下有两个用户a和b,两者都有各自的root文件夹进行訪问,而且同一时候都配置了各自的server。可是nginx的配置文件是在全局其作用的。

    那么假设在局域网中c訪问这个服务器的时候,那么究竟訪问哪个文件夹呢?

    后来,哥哥告诉我了。

    一般在上线的站点中配置nginx的时候。server_name是域名。依据不同的域名。nginx自然是知道怎么去转的。

    假设是在局域网中用ip进行訪问,假设存在着两个server,那么就配置一个当用ip进行訪问的时候,默认跳转到一个文件夹下就能够了。

    自己在线下进行折腾的时候。就配置一个人server就能够了。

    默认就会请求这个文件夹。并用fastccgi进行转发。


    在配置nginx的时候发现了一个问题,訪问的root文件夹下,.html结尾的静态文件是能够正常被訪问的,.php结尾的就不行。

    后来才发现。在进行配置的时候,将root变成了局部变量。导致匹配php文件的时候,找不到root。自然就找不到要訪问的文件了。

    最后的配置例如以下:


  • 相关阅读:
    【318】C# 学习笔记
    【317】python 指定浏览器打开网页 / 文件
    【316】python.requests 读取网页信息
    【315】Windows 之间代码自动传文件
    多线程经典问题-----乘客做公交车问题解答3
    VS2013/2012 下无法打开 源 文件“stdafx.h”的解决方法
    [课堂实践与项目]手机QQ客户端--4期(SQLite的加入,注册,找回,登录界面的修改):建立关于QQ注册类,使用SQLite进行存储,
    《Effective C++》学习笔记条款13 以对象管理资源
    抛弃编程语言的偏见——对话百度架构师
    IOS开发之UINavigationBar
  • 原文地址:https://www.cnblogs.com/wgwyanfs/p/6889232.html
Copyright © 2020-2023  润新知