LNMP的虚拟主机配置http和https

项目实战:
    搭建LNMP环境:Linux+Nginx+Mysql(MariaDB)+php(php-fpm),创建多个虚拟主机:
    主机1提供正常的http服务,用于安装wordpress博客;
    主机2提供正常的https服务,用于安装phpMyAdmin,用图形界面去管理MySQL(MariaDB)数据库;

项目实战步骤:
1.安装nginx:
    (1)使用已经下载好的nginx的rpm包进行安装:
        CentOS6:yum install -y nginx-1.6.2-1.el6.ngx.x86_64.rpm
        CentOS7:yum install -y nginx-1.10.0-1.el7.ngx.x86_64.rpm
    (2)使用阿里云的epel源进行直接安装
        CentOS6:http://mirrors.aliyun.com/epel/6/x86_64
        CentOS7:http://mirrors.aliyun.com/epel/7/x86_64
        yum -y install nginx
2.安装数据库:
        CentOS6:yum -y install mysql mysql-server
        CentOS7:yum -y install mariadb mariadb-server
        vim /etc/my.cnf
        [mysqld]
        skip_name_resolve=ON
        innodb_file_per_table=ON
        mysql_secure_installation(启动服务之后,进行初始化mysql数据库)
3.安装php的插件:
        yum install -y php-fpm php-mysql php-gd php-mcrypt php-mbstring
4.启动服务:
        CentOS6:
            service nginx start
            service mysqld start
            service php-fpm start
        CentOS7:
            systemctl start nginx.service
            systemctl start mariadb.service
            systemctl start php-fpm.service
5.关闭防火墙和SELinux:
        iptables -F
        setenforce 0
6.http配置wordpress;
    (1)配置php-fpm:
        vim /etc/php-fpm.d/www.conf
        将里面的user和group 由apache更改为nginx
        创建/var/lib/php/session并将其属主属组更改为nginx
        mkdir /var/lib/nginx/session
        chown -R nginx:nginx /var/lib/nginx/session
        systemctl restart php-fpm.service 
    (2)配置php-fpm的虚拟主机:
        将默认的default.conf进行备份:
        mv /etc/nginx/conf.d/default.conf{,.bak}
        新创建虚拟nginx主机的配置文件:
        vim /etc/nginx/conf.d/wordpress.conf
        server {
            listen 80;
            server_name www.sjsir.com;
            location / {
                root /var/www/html;
                index index.php index.html index.htm; 
            }
            location ~* \.(php)$ {
                root /var/www/html;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
                include fastcgi_params; 
            }

        }
    (3)搭建wordpress;(wordpress-4.6.1.zip设置界面为英文版)
        cd /var/www/html
        rz wordpress-4.6.1.zip
        unzip wordpress-4.6.1.zip
        rm -rf wordpress-4.6.1.zip
        mv wordpress/* .
    (4)为wordpress创建mysql数据库的数据;
        #mysql -uroot -p(root用户的mysql密码)
        mysql>CREATE DATABASE wordpress;
        mysql>GRANT ALL ON wordpress.* TO 'wordpress'@'127.0.0.1' IDENTIFIED BY 'wordpresspass';
        mysql>exit
    (5)用浏览器访问192.168.1.104:
        点击Let's go!
        blob.png

        按照之前设置的信息,将下面修改正确,之后Submit;

        blob.pngimages\4-2.png
        将上图蓝色中的内容复制下来,并创建后粘贴到/var/www/html/wp-config.php

        blob.pngimages\4-3.png
            vim /var/www/html/wp-config.php
            粘贴到此处
            回到浏览器点击Run the install 
            按照下图填入必要信息:
         blob.png

            然后会出现以下页面,表示安装成功;
        blob.png   
            登录wordpress,会发现英文版的wordpress-4.6.1已经安装成功:

        blob.pngimages\4-6.png
7.https配置pma:
    (1)配置pma的虚拟主机:
        server {
            listen 443 ssl;
            server_name www.sjsir.wang;
            ssl on;
            ssl_certificate /etc/nginx/ssl/nginx.crt;
            ssl_certificate_key /etc/nginx/ssl/nginx.key;
            ssl_session_cache shared:sslcache:20m;
            location / {
                root /var/www/pma;
                index index.php index.html index.htm;
            }
            location ~* \.(php)$ {
                root /var/www/pma;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME /var/www/pma$fastcgi_script_name;
                include fastcgi_params;
            }
        }
    (2)配置https:
        cd /etc/pki/CA/
        (umask 077;openssl -out private/cakey.pem 4096)
        openssl genrsa -new -x509 private/cakey.pem -out cecurt.pem
            CN Beijing Beijing Sjsir Ops ca.sjsir.cn
        touch index.txt
        echo 01 > serial
        cd /etc/nginx
        mkdir ssl
        cd ssl
        (umask 077;openssl genrsa -out nginx.key 4096)
        openssl req -new -key nginx.key -out nginx.csr

            CN Beijing Beijing Sjsir Ops ca.sjsir.cn

       openssl ca -in nginx.csr -out nginx.crt
    (3)配置pma:
        mkdir /var/www/pma
        cd /var/www/pma
        rz phpMyAdmin-4.0.5-all-languages.zip
        unzip phpMyAdmin-4.0.5-all-languages.zip
        mv phpMyAdmin/* .
        rm -rf phpMyAdmin/
        mv config.sample.inc.php config.inc.php 
    (4)测试:https://192.168.1.104
        就可以看到:

       blob.png
        输入账号和密码登录进去,就可以看到mariadb数据库:
        blob.png        
    注意:
        (1)在实验之前一定要关闭防火墙和SELinux,以免系统因为iptables和SELinux的设置而连接不上;
        (2)配置pma时,一定要配置php的fastcgi模块,或单独的php模块,不配置的话,用php编写的pma就无法使用;
        (3)配置pma时,一定要安装php-mcrypt模块,该模块位于epel源中(以阿里云的7系列的epel源:http://mirrors.aliyun.com/epel/7/x86_64)。
        (4)搭建该实验环境时,应该注意参考日志文件,以确定发生什么样的问题,/var/log/messages /var/log/nginx/error.log /var/log/nginx/access.log
            当测试时,发现无法连接服务器,例如500的错误,需要查看/var/log/nginx/error.log
            当测试时,发现页面能打开,但是不正常显示,而且/var/log/nginx/error.log日志无日志记录时,一定要去查看/var/log/nginx/access.log日志信息。有时服务器已经响应了,但是可能由于wordpress或pma的安装包配置的问题而报错,error.log不会存储这些已经响应的日志,需要去查看access.log。

原创文章,作者:sjsir,如若转载,请注明出处:http://www.178linux.com/56083

(0)
sjsirsjsir
上一篇 2016-10-30 16:48
下一篇 2016-10-30 16:52

相关推荐

  • linux中的几种压缩工具

    文件压缩 compress 不能自动补齐 .Z -d 解压缩 uncompress zcat X.Z > X -c 将结果打印到屏幕上,配合重定向,不会覆盖原文件,但权限会变。 -f 默认不对硬链接数为2及以上的文件压缩,加上f,强制压缩指定文件,而其他同inode的文件硬链接数减1. -v 显示详细过程。 ———&…

    2017-08-11
  • 人志建,则无敌—网络基本知识加简单脚本练习

    马哥21期网络班-8周博客作业 1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥:网桥就是把2个不同的网段桥接起来;可隔离冲突域。 集线器:集线器就是把多根以太网线或光纤集合连接在同一段物理介质下的装置;工作在物理层;不能隔离冲突域。 二层交换机:工作于OSI模型的第2层(数据链路层),故而称为二层交换机。二层交换技术的发…

    Linux干货 2016-08-29
  • N25-第四周

    复制/etc/ske1目录为/home/tuser1,要求/home/tuser及其内部文件的属组和其他用户均没有任何访问权限。 [root@localhost ~]# cp -a /etc/skel/ /home/tuser1[root@localhost ~]# ll -d /home/tuser1/drwxr-xr-x. 2 root root 59 …

    Linux干货 2016-12-25
  • 软件包管理rpm和yum基本使用

    RPM是RedHat Package Manager(RedHat软件包管理工具)类似Windows里面的“添加/删除程序”因而广受欢迎。逐渐受到其他发行版的采用。RPM套件管理方式的出现,让Linux易于安装,升级,间接提升了Linux的适用度。 rpm 执行安装包 二进制包(Binary)以及源代码包(Source)两种。二进制包可以直接安装在计算机中,…

    Linux干货 2016-08-29
  • 常见的文本处理工具及正则表达式的相关知识

    1.cat命令使用详解 cat [option]… [file]… -A equivalent=vET -b 非空行编号 -E 行为显示$ -n 显示所有行的行号 -s 行号并压缩连续空行为一行 -T 显示tab为^M 实例:显示a文件的行号及所有控制符 2.(1)head使用详解 head -n x 显示前x行 head -c x …

    Linux干货 2016-08-07
  • GNU awk

    awk -> gawk – 模式扫描和输出语言文件, pattern scanning and processing language 基本用法: gawk [options] 'program' FILE … program: PATTERN{ACTION ATATEMENTS} ACTION ATATEM…

    Linux干货 2016-09-22