Home  >  Article  >  Backend Development  >  nginx - 我看到 别人的 windows php有这样的配置 . 请问这样有什么好处吗 ?

nginx - 我看到 别人的 windows php有这样的配置 . 请问这样有什么好处吗 ?

WBOY
WBOYOriginal
2016-06-06 20:27:531087browse

<code>http {

upstream php_processes {
    server 127.0.0.1:9001 weight=1;
    server 127.0.0.1:9002 weight=1;
}


server {

        ## 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;
        }

}


}</code>

当然省略了好多 ... 好像是为了 php 多进程

回复内容:

<code>http {

upstream php_processes {
    server 127.0.0.1:9001 weight=1;
    server 127.0.0.1:9002 weight=1;
}


server {

        ## 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;
        }

}


}</code>

当然省略了好多 ... 好像是为了 php 多进程

目测是nginx的设置啊,你确定这个是PHP的配置文件?

首先,这是nginx配置文件,意思是把.php结尾的请求交给fastcgi解释器;
其次,php-fpm本身就是一个fastcgi的进程管理器,支持多进程,支持动态增减进程数;
再次,如果在网络上有多个不同的php-fpm,可以你给你nginx配置实现多机负载均衡;
最后,这样配的好处是,如果一个节点挂掉了,nginx可以把请求转到另一个上,实现高可用。

大哥这是nginx的反向代理的配置呀

这个是nginx的配置文件,不是PHP的配置,php的配置文件是php.ini

这不是nginx的配置吗?怎么变成php的啦

楼上都给赞 !!! 哈哈哈 嗯 确实是 nginx 反向代理配置 .

这是负载均衡的配置吧,方向代理在location里面

上面一堆答案都没说到重点。

<code>upstream php_processes {
    server 127.0.0.1:9001 weight=1;
    server 127.0.0.1:9002 weight=1;
}
</code>

为什么要开两个端口,9001和9002,也就是两个可执行的线程?
举例:

<code><?php echo file_get_contents("test.php");
?>
</code>

如果线程数只有一个,那么这个代码就会等待test.php的执行,然后test.php会等待这个php文件的执行结束……
于是,就"死锁"了……无限等待,然后30秒超时就跪掉了。
所以WNMP必须这么配置。
这个配置也只是用来本地测试下代码用而已。
要更专业的话,也不建议用Windows,也不会只给2个处理线程。
(下面那部分就是很常规的默认的Nginx的配置了,不解释)

楼上回答是正解,upstream 是Nginx的负载均衡配置,意思是按照相同的权重把请求分布到两个端口上,其用意自然也就是多个进程来处理任务,一是提高并发数量,第二就是防止文件锁等各种锁的发生

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn