文章目录
LNMP架构我没有换干净的环境,直接在上一个的LAMP架构上,卸载了apache
换成Nginx,这里主要记录Nginx和Apache的配置不同之处,项目上线的浏览器访问参照LAMP架构,我的截图只截访问界面,安装界面参照LAMP
LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。
Linux是目前最流行的免费操作系统。
Nginx是一个高性能的HTTP和反向代理服务器。轻量级 开源 免费
Mysql是一个小型关系型数据库管理系统。 mariadb
PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。
这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
LNMP架构部署
wordpress、farm、discuz、edusoho
nginx采用端口划分虚拟主机(nginx不需要在主配置文件里面添加监听端口)
10.11.67.32:81 wordpress(博客系统)
10.11.67.32:82 farm(QQ农场)
10.11.67.32:83 discuz(论坛系统)
10.11.67.32:84 edusoho(网校系统)
一、yum安装、开启、开机自启 NMP三大服务
[root@lamp-lnmp ~]# yum -y install mariadb mariadb-server php php-cli php-curl php-fpm php-intl php-mcrypt php-mysql php-gd php-mbstring php-xml php-dom
说明:经过LAMP架构的教训,php的插件该是安装的全乎点吧
官网安装最新版本nginx version: nginx/1.19.4
[root@lamp-lnmp ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/
r
e
l
e
a
s
e
v
e
r
/
releasever/
releasever/basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@lamp-lnmp ~]# yum -y install nginx
说明:centos7yum安装的是16版本,16版本的配置文件略有不同的,本次实验用nginx/1.19.4
[root@lamp-lnmp ~]# systemctl start mariadb php-fpm nginx
[root@lamp-lnmp ~]# systemctl enable mariadb php-fpm nginx
二、三大服务的配置&&项目上线
1、数据库配置
[root@lamp-lnmp ~]# mysqladmin password ‘123’
[root@lamp-lnmp ~]# mysql -p123(-p回车,密文输入密码,专业一点)
MariaDB [(none)]> create database wordpress;
MariaDB [(none)]> create database farm;
MariaDB [(none)]> create database ultrax;
MariaDB [(none)]> create database edusoho;
MariaDB [(none)]> exit
2、配置nginx服务(nginx是配置子配置文件)
[root@xingdian ~]# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
可以修改ip、端口、域名进行nginx虚拟主机的划分,可以更改网站默认发布目录
如果是php写的项目,在index加入 index.php
去掉以下行的注释:
location ~ .php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
d
o
c
u
m
e
n
t
r
o
o
t
document_root
documentrootfastcgi_script_name;
include fastcgi_params;
}
去掉注释,实现nginx和php的互相通讯,如果修改了网站发布目录,需要更改root下的目录,注意,如果网站默认发布目录没有改,也需要把root后面改成/usr/share/nginx/html,/scripts
改
为
改为
改为document_root$
10.11.67.32:81 wordpress(博客系统)虚拟主机配置
[root@lamp-lnmp ~]# cp /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/wordpress.conf
[root@lamp-lnmp ~]# vim /etc/nginx/conf.d/wordpress.conf
server {
listen 81;
server_name www.kakaops.com;
location / {
root /web/wordpress;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /web/wordpress;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@lamp-lnmp ~]# mkdir -pv /web/wordpress
[root@lamp-lnmp ~]# tar -xvf /mnt/wordpress-4.9.4-zh_CN.tar.gz
[root@lamp-lnmp ~]# mv wordpress/* /web/wordpress/
[root@lamp-lnmp ~]# rm -rvf wordpress/
[root@lamp-lnmp ~]# chmod 777 /web/wordpress/ -R
[root@lamp-lnmp ~]# systemctl restart mariadb
[root@lamp-lnmp ~]# systemctl restart php-fpm
[root@lamp-lnmp ~]# systemctl restart nginx
10.11.67.32:82 farm(QQ农场)虚拟主机配置
[root@lamp-lnmp ~]# cp /etc/nginx/conf.d/wordpress.conf /etc/nginx/conf.d/farm.conf
[root@lamp-lnmp ~]# vim /etc/nginx/conf.d/farm.conf
server {
listen 82;
server_name www.kakaops.com;
location / {
root /web/farm;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /web/farm;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@lamp-lnmp ~]# mkdir /web/farm
[root@lamp-lnmp ~]# unzip /mnt/farm-ucenter1.5.zip
[root@lamp-lnmp ~]# mv ./upload/* /web/farm/
[root@lamp-lnmp ~]# rm -rvf ./*
[root@lamp-lnmp ~]# chmod 777 /web/farm/ -R
10.11.67.32:83 discuz(论坛系统)虚拟主机配置
[root@lamp-lnmp ~]# cp /etc/nginx/conf.d/farm.conf /etc/nginx/conf.d/discuz.conf
[root@lamp-lnmp ~]# vim /etc/nginx/conf.d/discuz.conf
server {
listen 83;
server_name www.kakaops.com;
location / {
root /web/discuz;
index index.html index.htm index.php;
}
location ~ \.php$ {
root /web/discuz;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@lamp-lnmp ~]# mkdir /web/discuz
[root@lamp-lnmp ~]# unzip /mnt/Discuz_X3.4_SC_UTF8.zip
[root@lamp-lnmp ~]# mv upload/* /web/discuz/
[root@lamp-lnmp ~]# rm -rvf ./*
[root@lamp-lnmp ~]# chmod 777 /web/discuz/ -R
[root@lamp-lnmp ~]# systemctl restart mariadb
[root@lamp-lnmp ~]# systemctl restart php-fpm
[root@lamp-lnmp ~]# systemctl restart nginx
10.11.67.32:84 edusoho(网校系统)虚拟主机配置
[root@lamp-lnmp ~]# cp /etc/nginx/conf.d/discuz.conf /etc/nginx/conf.d/edusoho.conf
[root@lamp-lnmp ~]# vim /etc/nginx/conf.d/edusoho.conf
server {
listen 84;
server_name www.kakaops.com;
location / {
root /web/edusoho/web;
index index.html index.htm app.php;
}
location ~ \.php$ {
root /web/edusoho/web;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index *.php;
fastcgi_param SCRIPT_FILENAME /$document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@lamp-lnmp ~]# mkdir /web/edusoho
[root@lamp-lnmp ~]# tar -xvf /mnt/edusoho-7.5.12.tar.gz
[root@lamp-lnmp ~]# mv edusoho/* /web/edusoho/
[root@lamp-lnmp ~]# rm -rvf ./*
[root@lamp-lnmp ~]# chmod 777 /web/edusoho/ -R
[root@lamp-lnmp ~]# systemctl restart mariadb
[root@lamp-lnmp ~]# systemctl restart php-fpm
[root@lamp-lnmp ~]# systemctl restart nginx