nginx搭建下载站和动态网站

1.搭建视频资源下载网站

(1)准备数据

[root@web-8 ~]# mkdir /app/code/download
[root@web-8 ~]# touch /app/code/download/{1..10}.mp4

(2)编写配置文件

autoindex on:开启目录索引功能

autoindex_localtime on:显示本地时间

autoindex_exact_size off:显示精确文件的大小

[root@web-8 ~]# vim /etc/nginx/conf.d/good.download.cn.conf
[root@web-8 ~]# cat /etc/nginx/conf.d/good.download.cn.conf
server {
 listen 80;
 server_name good.download.cn;
 root /app/code/download/;
 charset utf8;
 error_log /var/log/nginx/good.download.cn-error.log notice;
 access_log /var/log/nginx/good.download.cn-access.log main;
 autoindex on;
 autoindex_localtime on;
 autoindex_exact_size off;
 location / {
 index index.html;

}
}
[root@web-8 ~]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

(3)在windows上做域名解析,访问网站

  (4)增加功能添加目录需要指定密码才能访问该目录

编写配置文件

[root@web-8 ~]# vim /etc/nginx/conf.d/good.download.cn.conf
[root@web-8 ~]# cat /etc/nginx/conf.d/good.download.cn.conf
server {
 listen 80;
 server_name good.download.cn;
 root /app/code/download/;
 charset utf8;
 error_log /var/log/nginx/good.download.cn-error.log notice;
 access_log /var/log/nginx/good.download.cn-access.log main;
 autoindex on;
 autoindex_localtime on;
 autoindex_exact_size off;
 location / {
 index index.html;

}
 location /4kmp4/ {
 auth_basic  "请输入密码:";
 auth_basic_user_file /etc/auth.passwd;
}
}

创建密码,修改对应权限

[root@web-8 ~]# htpasswd -bc /etc/auth.passwd admin 123456
Adding password for user admin
[root@web-8 ~]# chmod 600 /etc/auth.passwd 
[root@web-8 ~]# chown nginx.nginx /etc/auth.passwd 

打开windowd浏览器访问

2.搭建动态网站

(1) 安装数据库

[root@db-51 ~]# yum install mariadb-server -y

(2)启动数据库并设置开机自启

[root@db-51 ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@db-51 ~]# systemctl start mariadb

(3)设置数据库密码

[root@db-51 ~]# mysql_secure_installation

(4)进入创建数据库

MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';
Query OK, 0 rows affected (0.00 sec)

(5)安装php

[root@web-8 ~]# yum install php-fpm -y

(6) 修改php配置文件,将user改为nginx

[root@web-8 ~]# vim /etc/php-fpm.d/www.conf 
[root@web-8 ~]# grep -E  ^user|^group  /etc/php-fpm.d/www.conf 
user = nginx
group = nginx

(7) 编写配置文件

[root@web-8 ~]# vim /etc/nginx/conf.d/wordpress.conf
[root@web-8 ~]# cat /etc/nginx/conf.d/wordpress.conf
server {
  listen 80;
  server_name blog.wordpress.cn;
  root  /app/code/wordpress;
  error_log  /var/log/nginx/wordpress-error.log notice; 
  access_log /var/log/nginx/wordpresss-access.log main;
  location  / {
     index index.php;
  }
  location ~ \.php$ {
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index  index.php; 
    fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
    include   fastcgi_params;
  }
 }

(8) 解压wordpress代码到指定目录

[root@web-8 ~]# mv wordpress/*  /app/code/wordpress/
[root@web-8 ~]# ll /app/code/wordpress/
total 212
-rw-r--r--  1 root root   405 Feb  6  2020 index.php
-rw-r--r--  1 root root 19915 Jan  1  2022 license.txt
-rw-r--r--  1 root root  7437 Dec 29  2021 readme.html
-rw-r--r--  1 root root  7165 Jan 21  2021 wp-activate.php
drwxr-xr-x  9 root root  4096 May 14  2022 wp-admin
-rw-r--r--  1 root root   351 Feb  6  2020 wp-blog-header.php
-rw-r--r--  1 root root  2338 Nov 10  2021 wp-comments-post.php
-rw-r--r--  1 root root  3001 Dec 14  2021 wp-config-sample.php
drwxr-xr-x  5 root root    69 May 14  2022 wp-content
-rw-r--r--  1 root root  3939 Aug  3  2021 wp-cron.php
drwxr-xr-x 26 root root 12288 May 14  2022 wp-includes
-rw-r--r--  1 root root  2496 Feb  6  2020 wp-links-opml.php
-rw-r--r--  1 root root  3900 May 16  2021 wp-load.php
-rw-r--r--  1 root root 47916 Jan  4  2022 wp-login.php
-rw-r--r--  1 root root  8582 Sep 23  2021 wp-mail.php
-rw-r--r--  1 root root 23025 Dec  1  2021 wp-settings.php
-rw-r--r--  1 root root 31959 Oct 25  2021 wp-signup.php
-rw-r--r--  1 root root  4747 Oct  9  2020 wp-trackback.php
-rw-r--r--  1 root root  3236 Jun  9  2020 xmlrpc.php

(9) 修改属主属组权限

[root@web-8 ~]# chown  -R nginx.nginx /app/code/wordpress/

(10)重新加载nginx配置文件

[root@web-8 ~]# systemctl reload nginx.service 

(11) 修改windows的hosts文件,访问网址

(12)安装过程中错误总结:修改对应的属主属组权限,注意wordpress,mysql,php版本,版本不匹配wordpress无法部署,需要下载php-mysql模块,建立php与mysql的连接,否则无法部署。

  • 14
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值