• Nginx 服务器搭建


    什么是Nginx ?

      Nginx与Apache IIS等软件一样,是一款服务器软件,为web站点提供服务

      除此之外,Nginx 还是一款反向代理服务器,我们可以利用Nginx实现负载均衡

      所谓负载均衡是指为了减少服务器压力,需要将用户访问信息引入内部不同的服务器,分担服务器压力

    Nginx与其他服务器对比

      IIS:IIS服务器只能运行在Windows上,效率远不如Linux服务器

      Tomcat :面向java语言,是一款重量级服务器

      Apache : 目前应用最多的服务器软件,稳定,开源,跨平台,缺点是不支持高并发、rewrite模块强大

      Nginx : 轻量级、支持高并发(支持10万以上TCP连接)、部署简单、内存消耗小、成本低、rewrite模块不够强大

    Nginx服务器搭建

      安装环境Ubuntu16.04

      通过apt-get安装

    sudo apt-get install nginx
    

      然后安装PHPFastCGI管理器 php7.0-fpm

    sudo apt-get install php-fpm
    

      安装完成后配置 nginx 

    vim /etc/ngnix/sites-avaiable/default
    

      配置监听端口:

    listen 8080 default_server;       #IPV4端口
    listen [::]:8080 default_server;  #IPV6端口
    

      配置WEB根站点目录

    root /var/www/nginx/;
    

      配置nginx与php:

        nginx与fastcgi通信有2种方式:socket和TCP

    location ~ .php$ {
          include snippets/fastcgi-php.conf;   #取消注释这一行
          #       # With php7.0-cgi alone:
          #       fastcgi_pass 127.0.0.1:9000;
          #       # With php7.0-fpm:
          fastcgi_pass unix:/run/php/php7.0-fpm.sock;    #设置socket方式
    }
    

      重启ngnix

    service nginx restart
    

      测试配置文件是否生效

    /usr/sbin/nginx -t
    

      

      改php-fpm配置文件

    sudo vim /etc/php/7.0/fpm/pool.d/www.conf
    ; The address on which to accept FastCGI requests.
    ; Valid syntaxes are:
    ;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
    ;                            a specific port;
    ;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
    ;                            a specific port;
    ;   'port'                 - to listen on a TCP socket to all addresses
    ;                            (IPv6 and IPv4-mapped) on a specific port;
    ;   '/path/to/unix/socket' - to listen on a unix socket.
    ; Note: This value is mandatory.
    listen = /run/php/php7.0-fpm.sock   #与nginx配置文件中保持一致

      重启php-fpm

    service php7.0-fpm restart
    

      测试配置文件是否生效

    php-fpm7.0 -t
    

    至此就完成了nginx和PHP的搭建

    注意:当apache和nginx安装在同一台主机上时需要修改各自的监听端口,避免冲突

    apache:

    vim /etc/apache2/ports.conf 

    nginx:

    vim /etc/nginx/sites-avaiable/default
    

      

  • 相关阅读:
    绕口令系列 1
    毕业论文排版
    使用matlab表示“段数不确定”的分段函数
    [转]C/C++关于全局变量和局部变量初始化与不初始化的区别
    [转]基于Protel DXP软件的PCB高级编辑技巧大全
    冒泡排序及其优化
    gcc编译器参数
    [转]跟我一起写Makefile系列
    实例说明optimize table在优化mysql时很重要
    log4php0.9的详细配备实例说明
  • 原文地址:https://www.cnblogs.com/xiaoliwang/p/9311736.html
Copyright © 2020-2023  润新知