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