zoukankan      html  css  js  c++  java
  • 02-location ginx+php

    一、location

    # 作用: 控制用户请求 uri 的具体路径
    # 用法: location [ = | ~ | ~* | ^~ ] uri { ... }
    """多个location时会用上, 但多个location会出现优先级的问题."""

    1、Location优先级

    #    匹配符         匹配规则                          优先级
    #    =                精确匹配                          1 
    #    ^~               以某个字符串开头                   2
    #    ~                区分大小写的正则匹配                3
    #    ~*               不区分大小写的正则匹配              4
    #    /                通用匹配,任何请求都会匹配到         5
    http://location.kkkedu.com/index.html            location /
    http://location.kkkedu.com/documents/1.html        location /documents/
    http://location.kkkedu.com/images/1.gif            location ^~ /images/
    http://location.kkkedu.com/documents/1.jpg        location ~* .(gif|jpg|jpeg)

    2、Location具体使用

    server {
        listen 80;
        server_name location2.oldxu.com;
    
        # 通用匹配,任何请求都会匹配到
        location / {
            root html;
            index index.html;
        }
    
        # 精准匹配,必须请求的uri是/nginx_status
        location = /nginx_status {
            stub_status;
        }
    
        # 严格区分大小写,匹配以.php结尾的都走这个location    
        location ~ .php$ {
            default_type text/html;
            return 200 'php访问成功';
        }
    
        # 严格区分大小写,匹配以.jsp结尾的都走这个location 
        location ~ .jsp$ {
            default_type text/html;
            return 200 'jsp访问成功';
        }
    
        # 不区分大小写匹配,只要用户访问.jpg,gif,png,js,css 都走这条location
        location ~* .(jpg|gif|png|js|css)$ {
            return 403;
        }
    
        # 不区分大小写匹配
        location ~* .(sql|bak|tgz|tar.gz|.git)$ {
            deny all;
        }
    }

    二、Nginx+php

      --> wordpress

    LNMP架构

            L = Linux
            N = Nginx
            M ~= MySQL | Mariadb
            p ~= PHP   | Python

    1、LNMP架构安装

    php:

    [root@kkk-kkk ~]# rpm -e $(rpm -qa |grep php)   #卸载php5版本
    [root@kkk-kkk ~]# wget http://cdn.xuliangwei.com/php.zip
    [root@kkk-kkk ~]# unzip php.zip 
    [root@kkk-kkk ~]# yum localinstall php/*.rpm -y

    修改进程运行的身份

    [root@kkk-kkk ~]# sed -i 's#user = apache#user = nginx#g' /etc/php-fpm.d/www.conf 
    [root@kkk-kkk ~]# sed -i 's#group = apache#group = nginx#g' /etc/php-fpm.d/www.conf 

    启动php-fpm

    [root@kkk-kkk ~]# systemctl enable php-fpm
    [root@kkk-kkk ~]# systemctl start php-fpm

    nginx+php检查

    [root@kkk-kkk ~]# cat /etc/nginx/conf.d/php.kkkedu.com.conf
    server {
        listen 80;
        server_name php.kkkedu.com;
        root /code;
    
        location / {
            index index.php;
        }
    
        location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    [root@kkk-kkk ~]# cat /code/index.php 
            <?php
                phpinfo();
            ?>

    安装mariadb

    [root@kkk-kkk ~]# yum install mariadb mariadb-server -y
    [root@kkk-kkk ~]# systemctl enable mariadb
    [root@kkk-kkk ~]# systemctl start mariadb
    [root@kkk-kkk ~]# mysqladmin password 'Oldxu.com123'
    [root@kkk-kkk ~]# mysql -uroot -pOldxu.com123
    MariaDB [(none)]> 
    MariaDB [(none)]> create database wordpress charset utf8;

    测试php+MariaDB是否成功

    [root@kkk-kkk ~]# cat /code/mysql.php 
       <?php
        $servername = "localhost";
        $username = "root";
        $password = "Oldxu.com123";
    
        // 创建连接
        $conn = mysqli_connect($servername, $username, $password);
    
        // 检测连接
        if (!$conn) {
            die("Connection failed: " . mysqli_connect_error());
        }
        echo "php连接MySQL数据库成功";
        ?>
    [root@kkk-kkk ~]# php /code/mysql.php 
            php连接MySQL数据库成功

    2、部署Wordpress

    第一步: 下载代码,存储至指定位置,变更权限

    [root@kkk-kkk ~]# cd /code/
    [root@kkk-kkk code]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz
    [root@kkk-kkk code]# tar xf latest-zh_CN.tar.gz 
    [root@kkk-kkk code]# chown -R nginx.nginx wordpress/

    第二步: 编写Nginx配置文件

    [root@kkk-kkk code]# cat /etc/nginx/conf.d/blog.kkkedu.com.conf 
    server {
        listen 80;
        server_name blog.kkkedu.com;
        root /code/wordpress;
    
        location / {
            index index.php;
        }
    
        location ~ .php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include fastcgi_params;
        }
    }
    [root@kkk-kkk code]# nginx -t
    [root@kkk-kkk code]# systemctl reload nginx

    第三步: 配置域名解析.访问浏览器.安装该产品

    3、安装EduSoho

    mkdir /code

    cd /code
    rz #上传文件
    tar xf edusoho-8.2.17.tar.gz

    #注意:我们的进程能够以什么方式去访问一个文件或目录,取决于进程所运行的用户身份对该文件有什么权限

    修改权限

    chown -R nginx.nginx edusoho

    增加EduSoho nginx配置

    vi /etc/nginx/conf.d/edusoho.kkkedu.conf
    server {
        listen 80;
        server_name edu.kkkedu.com;
        root /code/edusoho/web;
        client_max_body_size 1024m;        #允许上传视频大小限制
        client_body_buffer_size 100m;    #缓冲区大小(太小会提示a client request body is buffered to a temporary)
    
        location / {
            index app.php;
            try_files $uri @rewriteapp;
        }
    
        location @rewriteapp {
            rewrite ^(.*)$ /app.php/$1 last;
        }
    
        location ~ ^/udisk {
            internal;
            root /code/edusoho/app/data/;
        }
    
        location ~ ^/(app|app_dev).php(/|$) {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_split_path_info ^(.+.php)(/.*)$;
            include fastcgi_params;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param  HTTPS              off;
            fastcgi_param HTTP_X-Sendfile-Type X-Accel-Redirect;
            fastcgi_param HTTP_X-Accel-Mapping /udisk=/code/edusoho/app/data/udisk;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 8 128k;
        }
    
        location ~* .(jpg|jpeg|gif|png|ico|swf)$ {
            expires 3y;
            access_log off;
            gzip off;
        }
    
        location ~* .(css|js)$ {
            access_log off;
            expires 3y;
        }
    
        location ~ ^/files/.*.(php|php5)$ {
            deny all;
        }
    
        location ~ .php$ {
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_split_path_info ^(.+.php)(/.*)$;
            fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
            fastcgi_param  HTTPS              off;
            include        fastcgi_params;
        }
    }

    重启nginx服务

    nginx -t
    systemctl restart nginx

    修改php.ini 配置文件,调整解析器支持的最大上传限制

    vim /etc/php.ini
    upload_max_filesize = 1024M
    post_max_size = 1024M
    
    systemctl restart php-fpm
    """
     上传视频
        课程->创建课程
        课程->管理课程-->
            课程文件-->添加视频
            计划任务-->添加章节-->添加视频-->发布
    
     修改图片
        运营->编辑区管理->首页顶部.轮播图
        系统->站点设置->网站Logo
        系统->站点设置->主题->管理
                    ->组件调整
                    ->配色方案
    """
  • 相关阅读:
    Java排序算法总结(转载)
    Java基础—数组(转载)
    Java基础—注解(转载)
    Java基础—枚举
    JVM虚拟机—JVM的类加载机制
    三,memcached服务的两种访问方式
    二,windows下安装memcached服务
    一,memcached的基本概念
    七,apache配置域名
    六,apache修改默认根文件路径
  • 原文地址:https://www.cnblogs.com/kongxiangqun/p/13811217.html
Copyright © 2011-2022 走看看