URL 统一资源定位符 网址
URI 统一资源标识符 范围更广
|------------URL------------------|
www.oldboyedu.com/images/lidao.jpg
|-------URI------|
Active connections: 1
server accepts handled requests
599 599 1223
Reading: 0 Writing: 1 Waiting: 0
Active connections: 1 当前的连接数量(已经建立的连接)
server accepts 服务器接收到的请求数量
server handled 服务器接处理的请求数量
server requests 用户一共向服务器发出多少请求
Reading: 0 当前nginx正在读取的用户请求头的数量
Writing: 1 当前nginx正在响应用户请求的数量
Waiting: 0 当前等待被nginx处理的 请求数量
htpasswd -b -c /etc/nginx/auth_conf oldboyedu oldboyedu
3.nginx配置调用
server {
listen 80;
server_name module.oldboy.com;
access_log off;
stub_status;
auth_basic "Auth access Blog Input your Passwd!";
auth_basic_user_file auth_conf;
}
[root@web01 /etc/nginx/conf.d]# htpasswd -bc /etc/nginx/htpasswd oldboy oldboy
Adding password for user oldboy
[root@web01 /etc/nginx/conf.d]# ll /etc/nginx/htpasswd
-rw-r--r-- 1 root root 45 Jun 6 09:15 /etc/nginx/htpasswd
[root@web01 /etc/nginx/conf.d]# chmod 600 /etc/nginx/htpasswd
[root@web01 /etc/nginx/conf.d]# ll /etc/nginx/htpasswd
-rw------- 1 root root 45 Jun 6 09:15 /etc/nginx/htpasswd
[root@web01 /etc/nginx/conf.d]# chown nginx.nginx /etc/nginx/htpasswd
[root@web01 /etc/nginx/conf.d]# ll /etc/nginx/htpasswd
-rw------- 1 nginx nginx 45 Jun 6 09:15 /etc/nginx/htpasswd
cat 01-www.conf
server {
listen 80;
server_name www.oldboy.com;
root html/www;
location / {
return 200 "location / \n";
}
location = / {
return 200 "location = \n";
}
location /documents/ {
return 200 "location /documents/ \n";
}
location ^~ /images/ {
return 200 "location ^~ /images/ \n";
}
location ~* \.(gif|jpg|jpeg)$ {
return 200 "location ~* \.(gif|jpg|jpeg)$ \n";
}
access_log off;
}
[root@web01 /etc/nginx/conf.d]# curl 10.0.0.7/oldboy.html
location /
[root@web01 /etc/nginx/conf.d]# curl 10.0.0.7/documents/alex.txt
location /documents/
[root@web01 /etc/nginx/conf.d]# curl 10.0.0.7/lidao/documents/alex.txt
location /
[root@web01 /etc/nginx/conf.d]# curl 10.0.0.7/oldboy.jpg
location ~* \.(gif|jpg|jpeg)
=
^~ 匹配的不匹配正则 优先匹配 (更优先)
~* 匹配正则不区分大小写
/documents
/
验证/documents 与 ~* 优先级
[root@web01 /etc/nginx/conf.d]# curl 10.0.0.7/documents/oldboy.jpg
location ~* \.(gif|jpg|jpeg)
#验证 ~* 与 ^~ 优先级
[root@web01 /etc/nginx/conf.d]# curl 10.0.0.7/images/oldboy.jpg
location ^~ /images/
[root@web01 /etc/nginx/conf.d]# nginx -t
nginx: [emerg] invalid variable name in /etc/nginx/conf.d/01-www.conf:18
nginx: configuration file /etc/nginx/nginx.conf test failed
www.oldboy.com/alex/lidao.txt
#B C E
location = / { ##www.etiantian.org www.etiantian.org/ www.etiantian.org/index.html
[ configuration A ]
}
location / { ##默认情况,无路可走 www.etiantian.org/oldboy/lidao.html
[ configuration B ]
}
location /documents/ { ##uri里 以 /documents 开始
oldboyedu.com/documents/dsfsadfasdf.html
oldboyedu.com/oldboy/documents
[ configuration C ]
}
location ^~ /images/ {
[ configuration D ]
}
location ~* \.(gif|jpg|jpeg)$ { ##~* 不区分大小写的正则匹配,以.gif或.jpg或.jpeg结尾
[ configuration E ]
}
搭建LNMP环境
[root@web01 /etc/nginx/conf.d]# curl -sI 10.0.0.7 |awk 'NR==1{print $2}'
200
[root@web01 /etc/nginx/conf.d]# curl -sw "%{http_code}\n" -o /dev/null baidu.com
200
yum remove php-mysql-5.4 php php-fpm php-common
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y install php71w php71w-cli php71w-common php71w-devel php71w-embedded php71w-gd php71w-mcrypt php71w-mbstring php71w-pdo php71w-xml php71w-fpm php71w-mysqlnd php71w-opcache php71w-pecl-memcached php71w-pecl-redis php71w-pecl-mongodb
yum install -y mariadb-server
[root@web01 /etc/nginx/conf.d]# ll
total 16
-rw-r--r-- 1 root root 206 Jun 6 11:58 01-www.conf.gz
-rw-r--r-- 1 root root 448 Jun 6 12:04 02-blog.conf
-rw-r--r-- 1 root root 488 Apr 23 22:34 default.conf.gz
-rw-r--r-- 1 root root 195 Jun 6 11:58 status.conf.gz
[root@web01 /etc/nginx/conf.d]# cat 02-blog.conf
server {
listen 80;
server_name blog.oldboy.com;
access_log /var/log/nginx/access_blog.log main;
root /usr/share/nginx/html/blog;
location / {
index index.php index.html index.htm;
}
location ~* \.(php|php5)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
##MySQL
[root@web01 ~]# systemctl start mariadb.service
[root@web01 ~]# ss -lntup |grep mysql
tcp LISTEN 0 50 *:3306 *:* users:(("mysqld",pid=4336,fd=13))
[root@web01 ~]# ps -ef |grep mysql
mysql 4174 1 0 12:08 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mysql 4336 4174 0 12:08 ? 00:00:00 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/mariadb.pid --socket=/var/lib/mysql/mysql.sock
root 4374 3551 0 12:08 pts/0 00:00:00 grep --color=auto mysql
#数据库基础操作 单词
##查看
show
###查看系统中所有数据库
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
###查看系统中所有的用户
MariaDB [(none)]> select user,host from mysql.user;
+------+-----------+
| user | host |
+------+-----------+
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | web01 |
| root | web01 |
+------+-----------+
6 rows in set (0.00 sec)
select
创建
创建数据库
MariaDB [(none)]> create database wordpress;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| wordpress |
+--------------------+
5 rows in set (0.00 sec)
###创建用户
grant all on wordpress.* to 'wordpress'@'172.16.1.%' identified by '123456';
grant all on wordpress.* to 'wordpress'@'localhost' identified by '123456';
所有权限 wordpress数据库.所有表 '用户名'@'172.登录' 密码是 123456
```
[root@web01 ~]# mysql -uwordpress -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 5.5.60-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
##php的配置
[root@web01 ~]# egrep -n '^user|^group' /etc/php-fpm.d/www.conf
8:user = nginx
10:group = nginx
[root@web01 ~]#
[root@web01 ~]#
[root@web01 ~]# systemctl restart php-fpm.service
[root@web01 ~]# ss -lntup|grep 9000
tcp LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",pid=15344,fd=9),("php-fpm",pid=15343,fd=9),("php-fpm",pid=15342,fd=9),("php-fpm",pid=15341,fd=9),("php-fpm",pid=15340,fd=9),("php-fpm",pid=15339,fd=7))
[root@web01 ~]# ps -ef |grep php
root 15339 1 0 12:42 ? 00:00:00 php-fpm: master process (/etc/php-fpm.conf)
nginx 15340 15339 0 12:42 ? 00:00:00 php-fpm: pool www
nginx 15341 15339 0 12:42 ? 00:00:00 php-fpm: pool www
nginx 15342 15339 0 12:42 ? 00:00:00 php-fpm: pool www
nginx 15343 15339 0 12:42 ? 00:00:00 php-fpm: pool www
nginx 15344 15339 0 12:42 ? 00:00:00 php-fpm: pool www
root 15348 3551 0 12:43 pts/0 00:00:00 grep --color=auto php
检查与测试
检查nginx与php 之间 是否有问题
[root@nginx /usr/share/nginx/html/blog]# cat info.php
<?php
phpinfo();
?>
检查php与mysql 之间 是否有问题
[root@nginx /usr/share/nginx/html/blog]# cat mysqli.php
<?php
$servername = "localhost";
$username = "wordpress";
$password = "123456";
// 创建连接
servername, password);
// 检测连接
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "php连接MySQL数据库成功";
?>
[root@web01 ~]# tar xf wordpress-5.2.1.tar.gz
[root@web01 ~]# ll
total 10944
drwxr-xr-x 5 nobody 65534 4096 May 22 02:24 wordpress
-rw-r--r-- 1 root root 11199196 Jun 6 09:25 wordpress-5.2.1.tar.gz
[root@web01 ~]# mv wordpress/* /usr/share/nginx/html/blog/
[root@web01 ~]# chown -R nginx.nginx /usr/share/nginx/html/blog/
网友评论