本环境是基于 Centos 7.8 系统构建Nginx学习环境
具体构建,请参考 Nginx-1.18.0 环境部署
Nginx作为一款非常优秀的Web服务器,同样支持动态站点的部署,和Apache一样,也可以部署LNMP,接下来我将相信介绍。
一、LNMP 部署
安装软件
[root@node01 ~]# yum install mariadb-server php php-mysql php-gd php-fpm -y
启动数据库
[root@node01 ~]# vim /etc/my.cnf
[mysqld]
character-set-server=utf8
[root@node01 ~]# systemctl enable --now mariadb
[root@node01 ~]# mysqladmin -uroot password '123'
修改Nginx服务配置文件
[root@node01 ~]# vim /etc/nginx/conf.d/host.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
修改php配置文件
[root@node01 ~]# vim /etc/php.ini
cgi.fix_pathinfo=0
date.timezone = 'Asia/shanghai'
启动服务
[root@node01 ~]# systemctl enable --now php-fpm
[root@node01 ~]# systemctl restart nginx mariadb
[root@node01 ~]# netstat -lnutp | grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 2658/nginx: master
[root@node01 ~]# netstat -lnutp | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 2879/mysqld
[root@node01 ~]# netstat -lnutp | grep php-fpm
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 2638/php-fpm: maste
二、测试
Nginx和php协调工作
[root@node01 ~]# echo "<?php phpinfo(); ?>" >/usr/share/nginx/html/test.php
mysql和php协调工作
三、应用部署
[root@node01 ~]# cd /usr/share/nginx/html/
[root@node01 html]# ll Discuz_X3.2_SC_UTF8.zip
-rw-r--r-- 1 root root 12486773 Sep 13 2017 Discuz_X3.2_SC_UTF8.zip
[root@node01 html]# unzip Discuz_X3.2_SC_UTF8.zip
[root@node01]# vim /etc/nginx/conf.d/host.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.php index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /usr/share/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
[root@node01 html]# systemctl restart nginx
浏览器访问:http://192.168.5.11/upload/
同意安装
修改权限
[root@node01 html]# cd upload/
[root@node01 upload]# chmod -R a+w config/ data/ uc_*
刷新,单机下一步
创建数据库、授权用户
[root@node01 ~]# mysql -uroot -p123
MariaDB [(none)]> create database ultrax;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> grant all on ultrax.* to wan@localhost identified by '123456';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
Bye
[root@node01 ~]#
单机下一步,安装
安装完成,登录论坛
进入管理后台
[root@node01 upload]# mv install/index.php install/index.php.bak