• nginx-1.16.0 (php)


     nginx-支持php

    1. 下载
      php-7.3.5.tar.bz2  
      nginx-1.16.0  nginx/Windows-1.16.0

    2. 安装php
      yum install gcc gcc++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc-devel glib2 glib2-devel gd
      ./configure --prefix=path --enable-fpm --with-mysql=path --with-pdo-mysql
      make && make install
      cp php.ini-development /usr/local/php/php.ini
      cp sapi/fpm/php-fpm /usr/local/bin
      cp /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf
      vim /usr/local/php/php.ini
          cgi.fix_pathinfo=0
      vim /usr/local/etc/php-fpm.conf
          ; Unix user/group of processes
          ; Note: The user is mandatory. If the group is not set, the default user's group
          ;       will be used.
          user = www-data
          group = www-data
      /usr/local/bin/php-fpm
      View Code
    3. 安装nginx
      [nginx-stable]
      name=nginx stable repo
      baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
      gpgcheck=1
      enabled=1
      gpgkey=https://nginx.org/keys/nginx_signing.key
      
      [nginx-mainline]
      name=nginx mainline repo
      baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
      gpgcheck=1
      enabled=0
      gpgkey=https://nginx.org/keys/nginx_signing.key
      View Code

      配置解析php

      location ~ .php$ {
          root           html;
          fastcgi_pass   127.0.0.1:9000;
          fastcgi_index  index.php;
          fastcgi_param  SCRIPT_FILENAME  /ust/Nginx/nginx/html$fastcgi_script_name;
          include        fastcgi_params;
      }
      View Code



     虚拟机

    1. 虚拟主机

      最少要有listen,基于端口区分

          server {
              listen 8002;
              root /opt/nginx/web2;
          } 
      View Code

      基于域名区分,在监听端口时,可以指定默认主机;

          server {
              listen 8000;
              server_name web1.donatello.cc;
              root /opt/nginx/web1;
          }   
      
          server {
              listen 8000 default_server;
              server_name web2.donatello.cc;
              root /opt/nginx/web2;
          }   
      
          server {
              listen 8000;
              server_name web3.donatello.cc;
              root /opt/nginx/web3;
          }  
      View Code
    2. location
      语法规则:
      synopsis:  location [=|~|~*|^~]  /uri/ {}
      =   精确匹配
      ~   区分大小写
      ~*  不区分大小写
      ^~  禁止表达式匹配
      View Code

      ftp 目录浏览

          server {
              listen 8000 default_server;
              server_name web2.donatello.cc;
              root /opt/nginx/web2;
      
              location /ftp {
                  autoindex on; 
              }   
              location /data {
      
              }
          }
      View Code

    代理&Http负载均衡

    1. 代理配置,转发到其他主机的指定端口
      location / { 
          proxy_pass http://donatello.cc:80;
      }
      View Code
    2. 负载均衡
      要使用 http 负载均衡,须在 nginx 配置文件 http 指令中使用 upstream 指令定义后台服务器组
      server {
          listen       80; 
          server_name  localhost;
      
          location / { 
              proxy_pass http://pinyou;
          }   
      
      }
      
      
          upstream pinyou {
              server www1.com:800;
              server www2.com:800;
              server www3.com:800;
              server www4.com:800;
          }   
      View Code

      简单粗暴的回话保持

          upstream pinyou {
              ip_hash;
              server www1.com:800 weight=1;
              server www2.com:800 weight=2;
              server www3.com:800 weight=3;
              server www4.com:800 weight=1;
          }  
      View Code

      NGINX Plus offers better solutions if session persistence is required.

          upstream pinyou {
              zone backend 64k;
              least_conn;
              server www1.com:800 weight=1;
              server www2.com:800 weight=2;
              server www3.com:800 weight=2;
              server www4.com:800 weight=1;
          } 
      View Code

      保险的方式,引入恢复的上游服务器:

      server www1.com:800 weight=1 slow_start=30s;
      View Code
    3. Nginx Plus
      Http KeepAlive,Nginx可以保留与上游服务器的 tcp 连接,从而提供响应速度。

      server {
          listen 80;
          location / {
              proxy_pass http://pinyou;
              proxy_http_version 1.1; # 1
              proxy_set_header Connection ""; # 2
           }
      }
      
      upstream backend {
          server server www1.com:800;
          server server www2.com:800;
      
          # maintain a maximum of 20 idle connections to each upstream server
          keepalive 20; # 3
      }
      View Code

      Health Checks


     error_page

    1. code
      400
      403 Forbidden  访问的uri默认页面不存在、目录不能浏览;
      404 Not Found  访问的资源uri不存在
      View Code

       

    Nginx .

    一切代码都是为了生活,一切生活都是调剂
  • 相关阅读:
    Python-24-Django(Model Form、Ajax、上传文件、KindEditor)
    P23-Django-model、Form补充 & 序列化
    P22-Django-Session、CSRF、Form、信号
    21-Python-Django进阶补充篇
    Python-Django进阶
    Python-18-Django 基础篇
    17-前端开发之jQuery
    15-前端开发之JavaScript
    14-前端开发之CSS
    14-前端开发之HTML
  • 原文地址:https://www.cnblogs.com/argor/p/10830449.html
Copyright © 2020-2023  润新知