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
下一篇 2016-10-30

相关推荐

  • 网络基础

    计算机网络     计算机网络,是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通信协议的管理和协调下,实现资源共享和信息传递的计算机系统。 1、网络通信设备     网络通信设备种类繁多,且日新月异,网络通信设备通常由网络线缆、网卡、集线器、中继器、网桥、交换机、路由器等组成。 网桥(Bri…

    Linux干货 2016-12-16
  • RPM及YUM工具介绍及使用(下)

    YUM工具 YUM工作原理 YUM工具的出现就是为了解决rpm工具不能够自动解决软件包之间的依赖关系这一难题的。它的工作原理大致如下:YUM透过分析RPM的标头资料,根据各软件的相关性找出软件所依赖的软件列表,然后去下载速度最快的yum仓库中下载所有相关RPM软件包,然后完成相应软件的安装。同时yum工具和rpm工具一样,也可以提供对软件包的查询,安装、升级…

    Linux干货 2016-12-26
  • 1128基于fastDFS,制作rpm包

    基于fastDFS,制作rpm包: 1、安装相应的环境: 1、Development tools 2、git(从外网git仓库下载源码所需) 3、Server Platform Development ———————————&#…

    2016-12-05
  • linux网络管理 一

    什么是网络?         是指将具有独立功能的计算机和周边设备,通过通信线路连接起来,在网络软件的支持下,实现资源的共享和数据的整个系统。 网络的特征:         速度      …

    2017-03-16
  • find详解(Blog 2)

    find与locate特性、find命令

    Linux干货 2017-11-08
  • Linux中的账号管理之命令的使用(中)

    linux中账号管理的命令非常多,我这里主要介绍最常见的几个命令,这些命令分别是针对用户和组的管理 主要介绍对用户管理的命令: 一、用户创建:useradd useradd命令用于Linux中创建的新的系统用户。useradd可用来建立用户帐号。帐号建好之后,再用passwd设定帐号的密码.而可用userdel删除帐号。使用useradd指令所建立的帐号,实…

    Linux干货 2016-08-07