zoukankan      html  css  js  c++  java
  • Nginx 中 fastcgi_pass 监听端口 unix socket和tcp socket差

     

    Nginx 中 fastcgi_pass 监听端口 unix socket和tcp socket差别

     

    Nginx连接fastcgi的方式有2种:unix domain socket和TCP,Unix domain socket 或者 IPC socket是一种终端,可以使同一台操作系统上的两个或多个进程进行数据通信。与管道相比,Unix domain sockets 既可以使用字节流和数据队列,而管道通信则只能通过字节流。Unix domain sockets的接口和Internet socket很像,但它不使用网络底层协议来通信。Unix domain socket 的功能是POSIX操作系统里的一种组件。

    TCP和unix domain socket方式对比

    TCP是使用TCP端口连接127.0.0.1:9000

    Socket是使用unix domain socket连接套接字/dev/shm/php-cgi.sock(很多教程使用路径/tmp,而路径/dev/shm是个tmpfs,速度比磁盘快得多)

    fastcgi_pass  unix:/tmp/php-cgi.sock
    fastcgi_pass  127.0.0.1:9000
    

    在服务器压力不大的情况下,tcp和socket差别不大,但在压力比较满的时候,用套接字方式,效果确实比较好。

    下面是php 5.3以上版本将TCP改成socket方式的配置方法:

    修改php-fpm.conf(/usr/local/php/etc/php-fpm.conf)

    ;listen = 127.0.0.1:9000
    listen = /dev/shm/php-cgi.sock
    

    修改nginx配置文件server段的配置,将http的方式改为socket方式

    location ~ .*.(php|php5)?$  {
                    #fastcgi_pass  127.0.0.1:9000;
                    fastcgi_pass   unix:/dev/shm/php-cgi.sock;
                    fastcgi_index index.php;
                    include fastcgi.conf;
            }
    

    重启php-fpm与nginx

    service nginx restart
    service php-fpm restart
    ls -al /dev/shm
    

    可以看到php-cgi.sock文件unix套接字类型

    理论上,unix socket 不走网络,效率高一些,但稳定性不是很理想,看这个测试:

    http://blog.csdn.net/liv2005/article/details/7741732

     
     
     
     
  • 相关阅读:
    Mac下配置Android adb环境变量
    在远程Linux上搭建jenkins
    早期渲染模板-Thymeleaf总结
    启动SpringBoot时的banner自定义修改
    MySQL密码策略及修改或忘记密码
    (转)Maven使用总结
    转-安全层开发—Shiro对比Spring Security
    JavaWeb应用-发布打成jar包和war包区别
    Gitea中常规git工作流程
    简述JSP与Servlet的区别及联系
  • 原文地址:https://www.cnblogs.com/brady-wang/p/5962561.html
Copyright © 2011-2022 走看看