美文网首页linux运维
CentOS LNMP (Linux+Nginx+MariaDB

CentOS LNMP (Linux+Nginx+MariaDB

作者: iOSDevLog | 来源:发表于2019-11-26 15:07 被阅读0次
    • Nginx( engIne x)是一个高性能的 Web 和反向代理服务器
    • NginX支持 HTTP、Https 和电子邮件代理协议
    • OpenResty 是基于 Nginx 和 Lua实现的 web 应用网关,集成了大量的第三方模块

    OpenResty 的下载和安装

    yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
    yum install openresty
    

    安装目录: /usr/local/openresty/
    html 目录:/usr/local/openresty/nginx/html

    OpenResty 配置文件

    /usr/local/openresty/nginx/conf/nginx.conf

    service openresty start | stop | restart | reload
    
    openresty.png

    虚拟主机

        server {
            listen       8000;
            listen       www.servera.com;
            server_name  servera;
            
            location / {
                root   html/servera;
                index  index.html index.htm;
            }
        }
    
        server {
            listen       8000;
            listen       www.serverb.com;
            server_name  serverb;
    
            location / {
                root   html/serverb;
                index  index.html index.htm;
            }
        }
    
    cd /usr/local/openresty/nginx/sbin/
    ./nginx -t # check conf
    ./nginx
    ps -ef | grep nginx
    ./nginx -s stop | reload
    ./nginx
    
    $ netstat -ntpl | grep nginx
    tcp        0      0 0.0.0.0:8000            0.0.0.0:*               LISTEN      17601/nginx: master 
    tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      17601/nginx: master
    

    vim /etc/hosts

    127.0.0.1   www.servera.com www.serverb.com
    

    test

    cd /usr/local/openresty/nginx/html
    mkdir servera serverb
    echo servera > servera/index.html
    echo serverb > serverb/index.html
    curl http://www.servera.com:8000
    servera
    curl http://www.serverb.com:8000
    servers
    

    LAMP

    MySQL安装

    • 可以使用 mariadb 替代

    yum install mariadb mariadb-server

    • 修改默认编码
      vim /etc/my.cnf.d/client.cnf
    [client]
    default-character-set=utf8
    

    vim /etc/my.cnf

    character_set_server=utf8
    init_connect='SET NAMES utf8'
    
    • systemctl start mariadb.service

    mysql

    MariaDB [(none)]> show variables like '%character_set%';
    +--------------------------+----------------------------+
    | Variable_name            | Value                      |
    +--------------------------+----------------------------+
    | character_set_client     | utf8                       |
    | character_set_connection | utf8                       |
    | character_set_database   | utf8                       |
    | character_set_filesystem | binary                     |
    | character_set_results    | utf8                       |
    | character_set_server     | utf8                       |
    | character_set_system     | utf8                       |
    | character_sets_dir       | /usr/share/mysql/charsets/ |
    +--------------------------+----------------------------+
    8 rows in set (0.01 sec)
    

    PHP 安装

    yum install php php-fpm php-mysql
    yum install php7 php7-fpm php7-mysql

    启动 php-fpm

    systemctl start php-fpm.service

    配置 nginx

    vim /usr/local/openresty/nginx/conf/nginx.conf

            location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include        fastcgi_params;
            }
    

    vim /usr/local/openresty/nginx/html/index.php

    <?php
    phpinfo();
    ?>
    

    相关文章

      网友评论

        本文标题:CentOS LNMP (Linux+Nginx+MariaDB

        本文链接:https://www.haomeiwen.com/subject/qoyewctx.html