【10.16】wordpress、discuz、域名重定向、用户认证

  • 4.34 安装wordpress
  • 4.35 安装discuz
  • 4.36 域名重定向
  • 4.37 用户认证

4.34 安装wordpress

1、下载安装包
2、解压 tar 包,将 wordpress 中的文件全部移动到虚拟主机指定文件存放目录中

[root@localhost blog.ars4life.com]#  wget https://cn.wordpress.org/wordpress-5.0.2-zh_CN.tar.gz
[root@alexis-01 blog.ars4life.com]# tar xvf wordpress-5.0.2-zh_CN.tar.gz
[root@localhost blog.ars4life.com]# mv wordpress/* ./
[root@localhost blog.ars4life.com]# rm -rf wordpress wordpress-5.0.2-zh_CN.tar.gz

3、创建库

[root@alexis-01 mysql]# mysql -uroot -p123456
MariaDB [(none)]> create database blog;
Query OK, 1 row affected (0.001 sec)MariaDB [(none)]> grant all on blog.* to 'blog'@'127.0.0.1' identified by '123456';
Query OK, 0 rows affected (0.001 sec)
  • 如果出现以下错误,那么需要重建/data/mysql/下的文件,重新安装以下 mariadb 即可
MariaDB [(none)]> create database blog;
ERROR 1006 (HY000): Can't create database 'blog' (errno: 2 "No such file or directory")

补充:
yum install -y expect //为了安装 mkpasswd命令,这个命令用来产生随机密码
mkpasswd -s 0 -l 12
-s 特殊字符数量
-l 密码长度

4、开始安装
浏览器输入 ip 地址



没有权限写wp-config.php文件
将 /data/wwwroot/blog.ars4life.com 目录中的需要写的文件权限改为 php-fpm,这里为了方便实验,就全部改掉

[root@alexis-01 mysql]# chown -R php-fpm /data/wwwroot/blog.ars4life.com/

完成后点现在就安装,重新填一遍参数,到这里点现在安装

填写相关参数

安装成功!

5、进入数据库,查看是否生成表

[root@alexis-01 mysql]# mysql -uroot -p123456
MariaDB [(none)]> use blog;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -ADatabase changed
MariaDB [blog]> show tables;
+-----------------------+
| Tables_in_blog        |
+-----------------------+
| wp_commentmeta        |
| wp_comments           |
| wp_links              |
| wp_options            |
| wp_postmeta           |
| wp_posts              |
| wp_term_relationships |
| wp_term_taxonomy      |
| wp_termmeta           |
| wp_terms              |
| wp_usermeta           |
| wp_users              |
+-----------------------+
12 rows in set (0.001 sec)

7、访问网页,也可以进入后台进行编辑了

  • 如果无法访问,那么查看一下几个方面
    1)文件权限不对
    2)网站根目录下面没有index文件
    3)selinux开启
    4)虚拟主机配置文件没有被识别

4.35 安装discuz

1、进入官网 https://www.discuz.net/forum.php,进入程序发布
2、找到 Comsenz 核心产品 Discuz! X3.4 正式版 帖子,进入https://gitee.com/ComsenzDiscuz/DiscuzX
3、复制右侧链接 https://gitee.com/ComsenzDiscuz/DiscuzX.git
4、linux机器上yum安装 git
5、将网络镜像克隆到本地

[root@alexis-01 ~]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
正克隆到 'DiscuzX'...
remote: Enumerating objects: 7668, done.
remote: Counting objects: 100% (7668/7668), done.
remote: Compressing objects: 100% (4898/4898), done.
remote: Total 7668 (delta 2858), reused 7332 (delta 2721)
接收对象中: 100% (7668/7668), 12.12 MiB | 3.34 MiB/s, done.
处理 delta 中: 100% (2858/2858), done.

补充:

  • 偶遇问题一记:
    在 git clone 时,出现以下错误
[root@alexis-01 ~]# git clone https://gitee.com/ComsenzDiscuz/DiscuzX.git
正克隆到 'DiscuzX'...
fatal: unable to access 'https://gitee.com/ComsenzDiscuz/DiscuzX.git/': Peer's Certificate has expired.
  • 解决方法:
[root@alexis-01 ~]# yum -y install ntp
[root@alexis-01 ~]# date
[root@alexis-01 ~]# chkconfig ntpd on
[root@alexis-01 ~]# ntpdate time.apple.com

也就是说,虚拟机时间和实际时间没有同步,需要安装 ntp 同步时间

6、DiscuzX 目录下的 upload 目录里内容全部拷贝到网站目录下,同时改名创建目录

[root@alexis-01 ~]# cp -r DiscuzX/upload/ /data/wwwroot/bbs.ars4life.com

7、创建虚拟主机配置文件 bbs.ars4life.com.conf

[root@alexis-01 conf.d]# vim bbs.ars4life.com.conf
server {listen       80;server_name  bbs.ars4life.com;location / {root   /data/wwwroot/bbs.ars4life.com;index  index.php index.html index.htm;}location ~ \.php$ {root           /data/wwwroot/bbs.ars4life.com;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /data/wwwroot/bbs.ars4life.com$fastcgi_script_name;include        fastcgi_params;}}

8、访问 bbs.ars4life.com,进入安装向导

9、查看状态是否全部正常

10、将 bbs.ars4life.com 目录下的文件权限全部改为 php-fpm

[root@alexis-01 bbs.ars4life.com]# chown -R php-fpm config data uc_server/data uc_client/data

11、刷新网页,发现当前状态全部变为绿色对钩

12、设置运行环境,选全部安装

13、数据库安装,先创建数据库

[root@alexis-01 bbs.ars4life.com]# mysql -uroot -p123456
MariaDB [(none)]> create database bbs;
Query OK, 1 row affected (0.001 sec)MariaDB [(none)]> grant all on bbs.* to 'bbs'@127.0.0.1 identified by '123456';
Query OK, 0 rows affected (0.018 sec)
[root@alexis-01 bbs.ars4life.com]# mysql -ubbs -p123456
ERROR 1045 (28000): Access denied for user 'bbs'@'localhost' (using password: YES)
[root@alexis-01 bbs.ars4life.com]# mysql -ubbs -p123456 -h 127.0.0.1
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| bbs                |
| information_schema |
| test               |
+--------------------+
3 rows in set (0.017 sec)

14、进入浏览器填写相关信息

15、等待完成安装

16、安装完成

4.36 域名重定向

  • 将一个域名重定向到另一个域名
    我们要将 444444.com 跳转到 bbs.ars4life.com
    1、编辑虚拟主机配置文件 bbs.ars4life.com.conf
    在 server_name 后增加需要的域名
    server_name bbs.ars4life.com 444444.com;

2、访问 444444.com 访问到了 bbs.ars4life.com

3、两个域名需要分清权重,需要重定向
在 bbs.ars4life.com.conf 中,server_name 下增加一段

    if ( $host = bbs.ars4life.com ){rewrite /(.*) http://444444.com/$1 permanent;}

$1就是前面的 (.*)

4、访问测试
访问 bbs.ars4life.com 被跳转到了 444444.com

5、可以 linxu 机器上 curl 测试

[root@alexis-01 bbs.ars4life.com]# curl -x127.0.0.1:80 -I bbs.ars4life.com
HTTP/1.1 301 Moved Permanently
Server: nginx/1.16.1
Date: Thu, 17 Oct 2019 04:58:23 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: http://444444.com/

在最后的 Location 显示了重定向到了地址

  • 状态码:
    200 正常
    404 不存在
    304 图片被缓存
    301 永久重定向
    302 临时重定向
    ★域名跳转,用301,不涉及域名跳转用302

4.37 用户认证

  • 用户认证使用目的: 实现二次认证,针对一些重要的目录(后台地址)

在 /etc/nginx/conf.d/bbs.ars4life.com.conf 中,server_name 下增加一段

    location  /admin.php{auth_basic              "Auth";auth_basic_user_file   /etc/nginx/user_passwd;}

location 后面指定需要访问的文件内容,访问此内容时需要认证
auth_basic 名称
auth_basic_user_file 用户密码文件


  • 将 root 和 index 改为全局的,去掉 location /
    又因为 location 又优先级的关系,而 ~ 先于 / 执行,那么在原先配置文件中,需要将 admin.php 前改为 ~

  • bbs.ars4life.com.conf 配置文件最终如下:

server {listen       80;server_name  bbs.ars4life.com;location ~ /admin.php{   auth_basic              "Auth";auth_basic_user_file   /etc/nginx/user_passwd;}root   /data/wwwroot/bbs.ars4life.com;index  index.php index.html index.htm;location ~ \.php$ {root           /data/wwwroot/bbs.ars4life.com;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /data/wwwroot/bbs.ars4life.com$fastcgi_script_name;include        fastcgi_params;}}
  • 创建两个用户名和密码,用于认证
    使用 htpasswd 创建用户名密码
    yum install -y httpd-tools 可以安装 htpasswd
[root@alexis-01 ~]# htpasswd -c /etc/nginx/user_passwd user1
New password:
Re-type new password:
Adding password for user user1
[root@alexis-01 ~]# htpasswd -m /etc/nginx/user_passwd user2
New password:
Re-type new password:
Adding password for user user2
[root@alexis-01 ~]# cat /etc/nginx/user_passwd
user1:$apr1$vHCe6de3$0jpnacw1bV6c6IxK/J4sp0
user2:$apr1$xSbtrfg9$hmq1esTX.zWwySKyTSVqR0

htpasswd -c:创建一个加密文件
-m:默认采用 MD5 算法对密码进行加密


  • 一定要记得检查语法是否正确,再重新加载
[root@alexis-01 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@alexis-01 ~]# nginx -s reload



对比上两张图,后一张是加上用户认证之后的,需要认证登录,输入之前创建的用户名和密码,才可以

如果输入用户名和密码之后,出现了admin.php被下载的情况,那么说明 php 文件没有被解析

  • 解决方法:

将配置文件中php解析相关语句放到 location ~ /admin.php 下,将内容改为

    location ~ admin.php{auth_basic              "Auth";auth_basic_user_file   /etc/nginx/user_passwd;fastcgi_pass   127.0.0.1:9000;fastcgi_index  index.php;fastcgi_param  SCRIPT_FILENAME  /data/wwwroot/bbs.ars4life.com$fastcgi_script_name;include        fastcgi_params;}

nginx location 优先级参考资料:
https://blog.csdn.net/arsenal4life/article/details/102615731
nginx location 配置语法规则参考资料:
https://blog.csdn.net/arsenal4life/article/details/102615769
原地址:
https://github.com/aminglinux/nginx/tree/master/location

【10.16】wordpress、discuz、域名重定向、用户认证相关推荐

  1. 4.36域名重定向4.37用户认证4.38Nginx访问日志4.39日志不记录静态文件4.40日志切割...

    2019独角兽企业重金招聘Python工程师标准>>> 域名重定向 用户认证 Nginx访问日志 日志不记录静态文件 日志切割 域名重定向 配置第二个域名: vi /etc/ngin ...

  2. Nginx默认虚拟主机、 Nginx用户认证、Nginx域名重定向、访问日志·····

    2019独角兽企业重金招聘Python工程师标准>>> Ngninx默认虚拟主机 1.vim /usr/local/nginx/conf/nginx.conf //增加 2.incl ...

  3. linux的Nginx安装、默认虚拟主机、用户认证、域名重定向配置介绍

    Nginx介绍 Nginx官网(http://nginx.org),最新版1.13,最新稳定版1.12 Nginx应用场景:web服务.反向代理.负载均衡 Nginx著名分支,淘宝基于Nginx开发的 ...

  4. Nginx安装、默认虚拟主机、Nginx用户认证、Nginx域名重定向

    12.6 Nginx安装 安装包下载到/usr/local/src目录 [root@taoyuan ~]# cd /usr/local/src [root@taoyuan src]# wget htt ...

  5. php nginx 域名重定向,Nginx默认虚拟主机、用户认证、域名重定向

    Nginx默认虚拟主机定义默认虚拟主机配置文件,在http下面加入include vhost/*.conf 在/usr/local/nginx/conf/下创建目录 #mkdir vhost/ //创 ...

  6. 12.6-12.9 Nginx安装,默认虚拟主机,用户认证,域名重定向

    12.6 Nginx安装 大纲 1 进入src目录,把nginx下载在此目录 #cd  /usr/local/src #wget http://nginx.org/download/nginx-1.8 ...

  7. 11-4 12 Nginx安装 默认虚拟主机 用户认证 域名重定向

    2019独角兽企业重金招聘Python工程师标准>>> 12.6 Nginx安装 12.7 默认虚拟主机 12.8 Nginx用户认证 12.9 Nginx域名重定向 扩展 ngin ...

  8. 笔记12(36-40)域名重定向,用户认证,nginx访问日志,日志切割

    学习笔记 域名重定向 配置第二个域名: vi /etc/nginx/conf.d/blog.aminglinux.cc.conf 在server_name 那一行的域名后面加一个域名,空格作为分隔 n ...

  9. 11.18 Apache用户认证 11.19/11.20 域名跳转 11.21 Apache访问日志

    2019独角兽企业重金招聘Python工程师标准>>> 11.18 Apache用户认证 htpasswd命令 >htpasswd命令是Apache的Web服务器内置工具,用于 ...

最新文章

  1. Docker映像和容器之间有什么区别?
  2. 关于计算机视觉(随谈)
  3. 第七章 综合练习 第四题
  4. python中类中属性和方法的具体定义方法和使用
  5. 【嵌入式】Libmodbus之RTU模式Slave端程序示例
  6. java存储过程示例_安全密码存储–请勿做的事和Java示例
  7. 有了数学基础,如何进阶AI?
  8. nodejs+mongodb+vue前后台配置ueditor
  9. HTML5(目前)无法帮你实现的五件事-多媒体
  10. Oracle 9.2.0.4的一个简单安装脚本(含安装前补丁p3006854)
  11. 20200716每日一句
  12. 接口测试用例设计的方法
  13. Vmware Vsphere HA
  14. 关于A6s上的无法动态修改maxLength的问题
  15. Swift 复数变量定义
  16. 使用Google时区API显示任何城市的实时本地时间
  17. 01背包总结+传授个人经验
  18. Vue学习记录-路由
  19. 虚拟内存(为什么要有虚拟内存)
  20. 有关QJ_Filecenter在vue中的使用和组件封装

热门文章

  1. excel下拉框超过255后office打开报部分内容有问题
  2. python少年_python简单入门
  3. 画矢量图上传iconfont并使用
  4. android和苹果内存,手机运行内存越大越好?4GB的苹果和8GB的安卓差别是什么?...
  5. 给所有曲解孔子的人[缠版论语篇](一)
  6. 一级运算放大器之套筒式与折叠式共源共栅
  7. QuteCom手记:phapi发送和接收音频数据的流程(ortp portaudio)
  8. 老供应商每次报价都略高于新供应商,该如何处理这种情况
  9. 打造一个云计算业的江左梅郎
  10. PHP关于open_basedir错误的解决方案