LNMP部署例項及HTTPS服務實現
LNMP部署例項及HTTPS服務實現
LNMP是什麼 : Linux+Nginx+Mysql+(php-fpm,php-mysql)
即在Linux作業系統上Nginx+Mysql+Php的網站服務架構。
CentOS 6中為MySQL,CentOS 7中為Mariadb
作用是什麼 : 提供web服務,並可以解析PHP類的應用程式;
下面我就利用LNMP架構部署phpMyAdmin:
前提:這次操作均在172.16.75.1主機上進行;
1. 為web伺服器配置一個域名:www.james.com
在物理機的C盤下的windows/System32/drivers/etc/etc/hosts檔案中新增一條記錄:
172.16.75.1 www.james.com
2. 在172.16.75.1主機上部署LNMP架構:
[[email protected] ~]# yum install nginx mariadb php-fpm php-mysql
在這估計大家會提出疑問,php-fpm,php-mysql的作用是什麼呢?
因為Nginx只是提供web服務,不能解析PHP應用,而php-fpm可以
而php-mysql用來連線PHP應用和Mariadb的;
3. 配置:
[[email protected] ~]# vim /etc/nginx/nginx.conf
[[email protected] ]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successfu
測試Nginx配置無錯,開啟服務:
[[email protected] ~]# systemctl start nginx
開啟php-fpm服務:
[[email protected] ~]# systemctl start php-fpm
建立一個目錄用於存放資源,在nginx.conf中已經定義:
[[email protected] ~]# mkdir -pv /myweb/nginx/
我事先已將wordpress和phpMyAdmin的包放到該目錄下:
首先部署phpMyAdmin(用來管理資料庫)應用
解壓:
[[email protected] ~]# cd /myweb/nginx/ [[email protected] nginx]# tar -xf phpMyAdmin-3.5.4-all-languages.tar.gz [[email protected] nginx]# mv phpMyAdmin-3.5.4-all-languages pma
在/var/lib/php下建立目錄session:
屬主為root,屬組為apache,許可權為770;
[[email protected] ~]# cd /var/lib/php [[email protected] php]# mkdir session [[email protected] php]# chown root:apache session/ [[email protected] php]# chmod 770 session/
給管理員配置一個數據庫的管理密碼:
[[email protected] ~]# mysqladmin -p'' password '111111' Enter password:
完成後,在web端進行訪問測試:
這樣phpMyAdmin部署完成。
接下來為phpMyAdmin提供https服務:
[[email protected] ~]# cd /etc/pki/CA/ [[email protected] CA]# (umask 077;openssl genrsa -out private/cakey.pem 2048) [[email protected] CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem -days 3653 [[email protected] CA]# touch index.txt [[email protected] CA]# echo 01 > serial
[[email protected] ssl]# (umask 077;openssl genrsa -out nginx.key 2048) [[email protected] ssl]# openssl req -new -key nginx.key -out nginx.csr -days 3653 [[email protected] ssl]# openssl ca -in nginx.csr -out /etc/pki/CA/certs/nginx.crt -days 3653 Using configuration from /etc/pki/tls/openssl.cnf Check that the request matches the signature Signature ok Certificate Details: Serial Number: 1 (0x1) Validity Not Before: Nov 12 14:15:57 2018 GMT Not After : Nov 12 14:15:57 2028 GMT Subject: countryName = CN stateOrProvinceName = Hebei organizationName = james organizationalUnitName = james.edu commonName = www.james.com X509v3 extensions: X509v3 Basic Constraints: CA:FALSE Netscape Comment: OpenSSL Generated Certificate X509v3 Subject Key Identifier: 5A:68:D6:47:29:DA:A5:29:98:09:0D:82:02:2D:B1:5D:61:8A:26:EC X509v3 Authority Key Identifier: keyid:32:B2:8D:AC:68:57:FC:BF:8B:F2:CA:68:8B:45:93:D4:7F:A2:25:F3 [[email protected] ssl]# scp /etc/pki/CA/certs/nginx.crt ./ [[email protected] ssl]# rm -f nginx.csr
修改nginx配置檔案:
[[email protected] ssl]# vim /etc/nginx/nginx.conf
檢測無誤後重啟nginx服務:
[[email protected] ssl]# nginx -t [[email protected] ssl]# nginx -s reload
web端測試:
https服務實現。