NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用

實驗需求:

在孫吳等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供網(wǎng)站建設(shè)、做網(wǎng)站 網(wǎng)站設(shè)計制作按需設(shè)計網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都全網(wǎng)營銷推廣,成都外貿(mào)網(wǎng)站制作,孫吳網(wǎng)站建設(shè)費用合理。

LNMP實現(xiàn)多個虛擬主機,部署wordpress和phpmyadmin,并為phpmyadmin提供https

實驗環(huán)境:

LNMP                 CentOS 7.2x86_64            IP:172.16.251.138

測試端              CentOS 6.7x86_64            IP:172.16.251.164

軟件包:

 initial-setup-ks.cfg
 mariadb-5.5.46-linux-x86_64.tar.gz
 nginx-1.10.0.tar.gz
 php-5.4.26.tar.bz2
 phpMyAdmin-4.4.14.1-all-languages.zip
 wordpress-4.3.1-zh_CN.zip

實驗準備:

安裝開發(fā)包組,支持軟件,解決依賴關(guān)系

[root@station138 ~]# iptables -F

[root@station138 ~]# setenforce 0

[root@station138 ~]# yum groupinstall"Development Tools" "Server Platform Development"

[root@station138 ~]# yum -y installpcre-devel openssl-devel zlib-devel

編譯安裝nginx:

[root@station138 ~]# tar xfnginx-1.10.0.tar.gz

1.創(chuàng)建程序用戶:

[root@station138 nginx-1.10.0]# useradd -rnginx

2.進入目錄開始編譯:

[root@station138 nginx-1.10.0]# ./configure--prefix=/usr/local/nginx --sbin-path=/usr/sbin/nginx--conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log--http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid--lock-path=/var/run/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_v2_module--with-http_dav_module --with-http_stub_status_module --with-threads--with-file-aio

[root@station138 nginx-1.10.0]# make&& make install

3.檢查配置文件:

[root@station138 nginx-1.10.0]# nginx -t

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok

nginx: configuration file /etc/nginx/nginx.conf test is successful

4.啟動服務(wù):

[root@station138 nginx-1.10.0]# nginx

[root@station138 nginx-1.10.0]# netstat-anpt |grep nginx

tcp   0    0 0.0.0.0:80           0.0.0.0:*           LISTEN    38873/nginx: master

5.創(chuàng)建虛擬主機:

[root@station138 ~]# mkdir -pv /var/www/v{1,2}

[root@station138 ~]# echo "web1" >> /var/www/v1/index.html

[root@station138 ~]# echo "web2" >> /var/www/v2/index.html

[root@station138 ~]# vim/etc/nginx/nginx.conf

server {

       listen       80;

       server_name  www.a.com;

       location / {

           root   /var/www/v1;

           index  index.php index.htmlindex.htm;

       }

}

server {

       listen       80;

       server_name  www.b.com;

       location / {

           root   /var/www/v2;

            index  index.php index.html index.htm;

       }

}

[root@station138 ~]# nginx -s reload

6.客戶端測試:

NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用

二進制安裝mariadb:

1.建立MySQL系統(tǒng)用戶

[root@station138~]# useradd -r -M mysql

2.建立數(shù)據(jù)存放的目錄

[root@station138~]# mkdir -p /testdir/mydata

[root@station138~]# chown -R mysql.mysql /testdir/mydata

3.解壓mariadb安裝包

[root@station138 ~]#tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local

[root@station138~]# ln -sv /usr/local/mariadb-5.5.46-linux-x86_64/ mysql 

[root@station138~]# chown -R root.mysql /usr/local/mysql/*

4.使用scripts腳本文件mysql_install_db文件來安裝數(shù)據(jù)庫

[root@station138mysql]# scripts/mysql_install_db --user=mysql --datadir=/testdir/mydata

5.提供配置文件

[root@station138mysql]# cp support-files/my-large.cnf /etc/my.cnf

[root@station138mysql]# vim /etc/my.cnf

datadir=/testdir/mydata        //指明mysql的數(shù)據(jù)存放路徑

innodb_file_per_table = ON   //成為獨立表空間

skip_name_resolve = ON       //跳過名稱解析

6.提供mysql服務(wù)啟動腳本

[root@station138 support-files]# cp mysql.server /etc/rc.d/init.d/mysqld  

[root@station138 support-files]# chkconfig --add mysqld

7.添加環(huán)境變量

[root@station138 ~]# vim /etc/profile.d/mysql.sh 

export PATH=/usr/local/mysql/bin:$PATH

[root@station138 ~]# source /etc/profile.d/mysql.sh

8.導出頭文件,導出庫文件:

[root@station138 ~]#ln -s /usr/local/include/ /usr/include/mysql

 [root@station138 ~]#vim /etc/ld.so.conf.d/mysql.conf

9.啟動服務(wù)

[root@station138 ~]# systemctl start mysqld 

[root@station138 ~]# ss -tnl 

LISTEN     0      50           *:3306     *:*  

源代碼安裝PHP:

1.安裝支持軟件,解決依賴關(guān)系:

[root@station138 ~]# yum -y install bzip2-devel libmcrypt-devel libxml2-devel openssl-devel

2.編譯php

[root@station138 ~]# tar xf php-5.4.26.tar.bz2 
[root@station138 ~]# cd php-5.4.26/

[root@station138 php-5.4.26]# ./configure\

 --prefix=/usr/local/php --with-openssl --with-mysql=mysqlnd

 --with-pdo-mysql=mysqlnd --with-mysql=mysqlnd --enable-mbstring 
--with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib
--with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt

--with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2

[root@station138 php-5.4.26]# make && make install

3.php提供配置文件

[root@station138 php-5.4.26]# cp php.ini-production /etc/php.ini

4.提供php-fpm腳本

[root@station138 php-5.4.26]# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@station138 php-5.4.26]# chmod +x /etc/rc.d/init.d/php-fpm 

[root@station138 php-5.4.26]# chkconfig --add php-fpm

5.提供php-fpm配置文件

[root@station138 php-5.4.26]# cd /usr/local/php

[root@station138 php-5.4.26]# cp etc/php-fpm.conf.default etc/php-fpm.conf

6.啟動服務(wù)

[root@station138 php-5.4.26]# systemctl start php-fpm
[root@station138 php-5.4.26]# ss -tnl 
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              

LISTEN      0      128       127.0.0.1:9000                          *:*

7.配置nginx支持php解析:

[root@station138 ~]# vim/etc/nginx/nginx.conf

 server {
        listen       80;
        server_name www.a.com;

  location / {
            root   /var/www/v1;
            index  index.php index.html index.htm;
        }
error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

location ~ \.php$ {
            root           /var/www/v1;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/v1/$fastcgi_script_name;
            include        fastcgi_params;
        }

}

 server {
              listen       80;
             server_name  www.b.com;
             location / {
                        root   /var/www/v2;
                        index  index.php index.html index.htm;
             }
        location ~ \.php$ {
            root           /var/www/v2;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  /var/www/v2/$fastcgi_script_name;
            include        fastcgi_params;
        }

[root@station138 ~]# nginx -s reload

8.客戶端測試php:

NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用

9.創(chuàng)建數(shù)據(jù)庫,授權(quán)用戶

[root@station138 nginx]# mysql -uroot –p

MariaDB [(none)]> create database wpdb;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wpdb.* to 'wpuser'@'172.16.%.%' identified by 'wp123';

Query OK, 0 rows affected (0.14 sec)

MariaDB [(none)]> create database pma;

Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on pma.* to 'pmauser'@'172.16.%.%' identified by 'pma123';

Query OK, 0 rows affected (0.00 sec)

10.測試mysql-php:

[root@station138 ssl]# cat /var/www/v1/index.php
web1
<?php
 $link = mysql_connect('localhost','root','123456');
 if($link)
  echo "OK";
 else
  echo "no";
?>

NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用

部署應(yīng)用:

1.部署wordpress:

[root@station138 ~]# unzip wordpress-4.3.1-zh_CN.zip

[root@station138 ~]# mv wordpress /var/www/v1/

[root@station138 wordpress]# mv wp-config-sample.php wp-config.php

[root@station138 wordpress]# vim wp-config.php 
/** WordPress數(shù)據(jù)庫的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL數(shù)據(jù)庫用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數(shù)據(jù)庫密碼 */
define('DB_PASSWORD', 'wp123');
/** MySQL主機 */

define('DB_HOST', '172.16.251.138');

2.部署phpMyAdmin:

[root@station138 ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
[root@station138 ~]# mv phpMyAdmin-4.4.14.1-all-languages /var/www/v2
[root@station138 v2]# ln -sv phpMyAdmin-4.4.14.1-all-languages/ pma
[root@station138 v2]# vim phpmyadmin/libraries/config.default.php
$cfg['blowfish_secret'] = 'tSQRO02T+grA6rvJHCXr';
$cfg['Servers'][$i]['host'] = '172.16.251.138'; 
$cfg['Servers'][$i]['user'] = 'pmauser';

$cfg['Servers'][$i]['password'] = 'pma123';

3.客戶端測試應(yīng)用:

NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用

為phpmyadmin提供https:

1.生成私鑰:

[root@station138 CA]# (umask 077; opensslgenrsa -out private/cakey.pem 2048)

2.生成自簽證書:

[root@station138 CA]# openssl req -new-x509 -key private/cakey.pem -out cacert.pem 

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:bj

Locality Name (eg, city) [Default City]:bj

Organization Name (eg, company) [DefaultCompany Ltd]:yw

Organizational Unit Name (eg, section)[]:Ops

Common Name (eg, your name or your server'shostname) []:www.b.com

Email Address []:admin@b.com

3.提供輔助文件

[root@station138 CA]#touch index.txt

[root@station138 CA]#echo 01 > serial

4.生成私鑰:

[root@station138 ssl]#  (umask 077; openssl genrsa -out nginx.key1024)

5.生成證書請求:

[root@station138 ssl]#  openssl req -new -key nginx.key -outnginx.csr

Country Name (2 letter code) [XX]:CN

State or Province Name (full name) []:bj

Locality Name (eg, city) [Default City]:bj

Organization Name (eg, company) [DefaultCompany Ltd]:yw

Organizational Unit Name (eg, section)[]:Ops

Common Name (eg, your name or your server'shostname) []:www.b.com

Email Address []:admin@b.com

Please enter the following 'extra'attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

6.簽發(fā)證書:

[root@station138 ssl]#  openssl ca -in /testdir/nginx.csr -out/etc/pki/CA/certs/nginx.crt

[root@station138 ssl]# cp/etc/pki/CA/certs/nginx.crt /etc/nginx/ssl/

7.修改nginx配置文件,添加支持ssl:

[root@station138 ~]# vim /etc/nginx/nginx.conf

server {
        listen       443 ssl;
        server_name  localhost;

        ssl_certificate      /etc/nginx/ssl/nginx.crt;
        ssl_certificate_key  /etc/nginx/ssl/nginx.key;

        ssl_session_cache    shared:SSL:1m;
        ssl_session_timeout  5m;

        ssl_ciphers  HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers  on;

        location / {
            root   html;
            index index.php index.html index.htm;
        }
    }

8.測試https:

NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用

分享題目:NGINX網(wǎng)站服務(wù)-LNMP平臺及應(yīng)用
文章源于:http://muchs.cn/article18/pdpogp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供Google網(wǎng)站設(shè)計、企業(yè)網(wǎng)站制作、App設(shè)計外貿(mào)建站、網(wǎng)站設(shè)計公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都定制網(wǎng)站網(wǎng)頁設(shè)計