一、知识点回顾

临时:关闭当前正在运行的
/etc/init.d/iptables stop
永久:关闭开机自启动
chkonfig iptables off ll /var/log/secure # 用户访问系统的记录,谁在什么时间链接了你的服务器,什么时候链接了 #安装lrzsz
yum install lrzsz -y
rz #windows文件上传到linux
sz #吧linux文件下载到windows
rpm -pa lrzsz #查看安装好了没有 .tar.gz
.zip #这种格式的压缩包是linux和windows默认支持的
unzip secure-20161219.zip #解压 xshell #远程连接
xftp #ftp工具
https://www.netsarang.com/download/down_form.html?code=523 #查看文件内容用cat ,,看日志的时候不用这个
#查看日志
1、less
2、head/dail
3、grep
f或空格 #向下翻页
b #想上翻页
grep 'Failed password' secure-20161219

二、练习题

1、简述一下linux的启动过程

  • 按下电源
  • 开机自检(检查内存cpu 硬件是否有问题)
  • MBR引导 #默认从硬盘的MBR启动
  • GRUB菜单 #启动的时候3 2 1 那个就是CRUB菜单
  • 加载内核
  • 运行INIT进程 #linux的第一个进程
  • 读取/etc/inittab配置文件
  • 执行/etc/rc.d/rc.sysinit脚本
  • 执行/etc/rc.d/rc脚本 #根据系统的运行级别,在开机的时候启动不同的软件
  • 启动mungetty进程

2、http的请求与响应过程

  • 1、域名解析
  • 2、浏览器发送tcp请求,建立tcp三次握手
  • 3、发送http请求,
  • 4、服务器收到请求返回给浏览器
  • 5、浏览器收到返回的结果,在页面进行渲染,解析HTML代码
  • 6、关闭连接

请求包括的:

  • 请求首行
  • 请求头
  • 空行
  • 请求体

响应包括的:

  • 响应首行
  • 响应头
  • 空行
  • 响应体
    curl www.baidu.com  #显示响应的内容
curl -v www.baidu.com #显示请求和响应的过程
> 表示请求
< 表示响应

三、nginx

Ngix是web服务器,跟apache一样,它可以做动态请求转发、web端负载均衡、反向代理等等;
tomcat是应用服务器,当然如果非用逼良为娼,也可做web服务器用,它主要是做Servlet容器用的,一般用在应用层,运行后台逻辑代码,访问数据库服务器等; 一般常见的网站,采用apache+tomcat+数据库或是Ngix+tomcat+数据库这三层物理架构;如果是大型网站应用,上面还会有一层硬件负载均衡F5。 从性能角度来讲Ngix的性能似乎要比apache略好,但从使用方便上来看,apache配置起来更方便,功能上都很强大,因为apache名气似乎更大一些,用的人就更多一些。

1、下载

[root@s6haiyanvm ~]# wget http://nginx.org/download/nginx-1.12.2.tar.gz
ll -h nginx-1.12.2.tar.gz #查看多大
tar xf nginx-1.12.2.tar.gz #解压
cd nginx-1.12.2.tar.gz
ls -l
12一般偶数版的是稳定版本 ,基数是测试版

2、编译安装nginx前的准备

useradd -s /sbin/nplogin -M www #添加一个用户,-s和-M是吧用户变成虚拟用户号
id www
su - www

3、安装nginx的依赖包

#pcre-devel     perl语言的兼容正则表达式
#openssl-devel https
yum install pcre-devel -y
yum install openssl-devel -y
rpm -qa pcre-devel

4、编译安装nginx

pwd      #应该是在这个路径下/application/nginx-1.12.2
./configure --help
(1)./configure --user=www --group=www --prefix=/application/nginx-1.12.2 --with-http_stub_status_module --with-http_ssl_module
--user :用户
--group : 用户组
--prefix :安装到哪里
两个模块: --with-http_stub_status_module --with-http_ssl_module
tree -L echo $? #表示以上一次的执行情况 ,返回0表示正确,返回1表示错误
(2)make #根据一些配置进行编译
(3)make install md5sum nginx/1.12.2.tar.gz #给这个压缩包创建个指纹,相当于身份证

5、查看

/application/nginx-1.12.2/sbin/nginx -t #检查是否语法错误
/application/nginx-1.12.2/sbin/nginx #执行命令
ss -lntup|grep 80 #查看安装好了没有
10.0.0.200 #在浏览器里面看页面,看搭建好了没有
curl -v 10.0.0.200 #在linux里面查看

6、nginx的常用配置

[root@oldboyedu-s6 nginx-1.12.2]# pwd
/application/nginx-1.12.2
[root@oldboyedu-s6 nginx-1.12.2]# ll
total 36
drwx------ 2 www root 4096 Mar 15 10:31 client_body_temp
drwxr-xr-x 2 root root 4096 Mar 15 10:00 conf nginx配置文件的目录
drwx------ 2 www root 4096 Mar 15 10:31 fastcgi_temp
drwxr-xr-x 2 root root 4096 Mar 15 10:00 html nginx站点目录 网站的根目录
drwxr-xr-x 2 root root 4096 Mar 15 10:31 logs nginx日志
drwx------ 2 www root 4096 Mar 15 10:31 proxy_temp
drwxr-xr-x 2 root root 4096 Mar 15 10:00 sbin nginx命令
drwx------ 2 www root 4096 Mar 15 10:31 scgi_temp
drwx------ 2 www root 4096 Mar 15 10:31 uwsgi_temp

├── client_body_temp
├── conf
│   ├── fastcgi.conf
│   ├── fastcgi.conf.default
│   ├── fastcgi_params
│   ├── fastcgi_params.default
│   ├── koi-utf
│   ├── koi-win
│   ├── mime.types
│   ├── mime.types.default
│   ├── nginx.conf #nginx的主配置文件 
│   ├── nginx.conf.default
│   ├── scgi_params
│   ├── scgi_params.default
│   ├── uwsgi_params
│   ├── uwsgi_params.default
│   └── win-utf
├── fastcgi_temp
├── html
│   ├── 50x.html
│   └── index.html #网站默认的首页文件 
├── logs
│   ├── access.log #访问日志
│   ├── error.log
│   └── nginx.pid
├── proxy_temp
├── sbin
│   └── nginx
├── scgi_temp
└── uwsgi_temp

#修改配置文件
egrep '#' #查看包含#的 egrep '^$' #空行
egrep '^$|#' conf/nginx.conf #排除空行或者#
egrep '^$|#' conf/nginx.conf.default > conf/nginx.conf
修改了配置文件记得重启一下
/application/nginx-1/sbin/nginx -s reload #优雅的重启
/application/nginx-1/sbin/nginx -s stop #优雅的停止(迫不得已才用的) /application/nginx-1/sbin/nginx

四、搭建一个小网站

1、修改nginx.conf文件

worker_processes  1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

2.创建环境

mkdir -p /application/nginx-1.12.2/html/{www,bbs,blog}  #创建多级目录
for name in www bbs blog;do echo $name.etiantian.org> /application/nginx-1.12.2/html/$name/index.html ;done
for name in www bbs blog;do cat /application/nginx-1.12.2/html/$name/index.html ;done

3.检查语法并重启

[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -t
nginx: the configuration file /application/nginx-1.12.2/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.12.2/conf/nginx.conf test is successful
[root@oldboyedu-s6 nginx-1.12.2]# /application/nginx-1.12.2/sbin/nginx -s reload

4.windows测试 浏览器(注意缓存)

    (1)方式一:cat /etc/hosts  #修改host,域名解析

    10.0.0.200  www.etiantian.org bbs.etiantian.org blog.etiantian.org
www.eitiantian.org #浏览器输入测试 (2)方式二:
curl -H Host:www.etiantian.org 10.0.0.200 #修改host里面的host

5、排错流程:

1.linux命令行是否能显示
curl -vH Host:www.etiantian.org 10.0.0.200 2.windows 本地shell
ping

6、搭建多个

[root@oldboyedu-s6 nginx-1.12.2]# cat conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name www.etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server {
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
} } [root@oldboyedu-s6 nginx-1.12.2]# curl -H Host:bbs.etiantian.org 10.0.0.200
bbs.etiantian.org
[root@oldboyedu-s6 nginx-1.12.2]# curl -H Host:blog.etiantian.org 10.0.0.200
blog.etiantian.org

五、参数location的理解

“~”用于区分大小写(大小写敏感)的匹配;   ~ /images {}

“~*” 用于不区分大小写的匹配。还可以用逻辑操作符!对上面的匹配取反,即!~ 和 !~*。

“^~”作用是在常规的字符串匹配检查之后,不做正则表达式的检查,即如果最明确的那个字符串匹配的location配置中有此前缀,那么不做正则表达式的检查。
[root@oldboyedu-s6 nginx-1.12.2]# cat  conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65; server {
listen 80;
server_name www.etiantian.org etiantian.org;
root html/www;
location / {
return 401;
} location /documents/ {
return 403;
}
location ^~ /images/ {
return 404;
}
location ~* \.(gif|jpg|jpeg)$ {
return 500;
}
}
} ^~
~*
/documents/
/ 第1名:“location ~* \.(gif|jpg|jpeg)$ {” 正则匹配
第2名:“location /documents/ {” 匹配常规字符串,如果有正则则优先匹配正则。
第3名:“location / {” 所有location都不能匹配后的默认匹配。 [root@oldboyedu-s6 nginx-1.12.2]# curl -I 10.0.0.200
HTTP/1.1 401 Unauthorized
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:13:41 GMT
Content-Type: text/html
Content-Length: 195
Connection: keep-alive [root@oldboyedu-s6 nginx-1.12.2]#
[root@oldboyedu-s6 nginx-1.12.2]# curl -I 10.0.0.200/documents/index.html
HTTP/1.1 403 Forbidden
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:14:42 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive [root@oldboyedu-s6 nginx-1.12.2]# curl -I 10.0.0.200/documents/w.jpg
HTTP/1.1 500 Internal Server Error
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:15:56 GMT
Content-Type: text/html
Content-Length: 193
Connection: close [root@oldboyedu-s6 nginx-1.12.2]#
[root@oldboyedu-s6 nginx-1.12.2]# curl -I 10.0.0.200/images/www.jpg
HTTP/1.1 404 Not Found
Server: nginx/1.12.2
Date: Thu, 15 Mar 2018 04:16:52 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive

linux学习:【第4篇】之nginx的更多相关文章

  1. linux学习(小白篇)

    当前服务器:centos 7 shell命令框:xshell 文件预览及上传:xftp (界面化软件,非常好用) 数据库连接:navicat 此文是在学习linux时做一个指令合集,方便自己查阅 进文 ...

  2. linux学习笔记-前篇

    大学毕业已经快三年了,从事嵌入式开发的工作也快三年了. 不过,老干些裸机开发,感觉很是枯燥,一咬牙一跺脚,决定从今天开始学习Linux操作系统,顺便记录下学习过程中所遇到的问题与心得. 自己从前完全没 ...

  3. 小白的linux学习笔记10:安装nginx和第一个网页

    sudo yum install nginx sudo systemctl status nginx sudo systemctl start nginx 检查端口:netstat -tlpn sud ...

  4. 克隆虚拟机以及两台linux机器相互登录:linux学习第四篇

    克隆虚拟机 1.      克隆 之后自己命名克隆的虚拟机并自己选择存放位置,完成克隆 2.      克隆虚拟机之后对新的虚拟机修改网络配置,以免冲突(将配置文件里的UUID去掉,并修改IP地址) ...

  5. linux学习笔记命令篇1---命令ls

    前言:  linux中接触最多的就是命令和文件. 命令 命令是有其格式的, 一般格式是command [option] parameter1 parameter2 [paramete3 ...]: 注 ...

  6. 单用户模式与救援模式:linux学习第三篇

    单用户模式 1.      重新启动,在下列界面选项第一项按 e 按e后进入此grub界面(启动工具) 2.      找到linux16所在行,将'ro'(只读)修改为'rw'(读写),并加上 in ...

  7. linux学习笔记基础篇(一)

    一.IP操作 1.临时修改IP ,执行命令  ifconfig  网卡名称  新ip :例如 ifconfg  nescc 192.168.1.110 ,重启失效 2.重启网络 ,执行命令 syste ...

  8. LINUX学习之一基础篇

    1.计算机硬件五大单元:运算器.控制器.存储器.I/O设备 2.CPU种类:精简指令集(RISC)和复杂指令集(CISC) 3.1Byte=8bit,扇区大小为512bytes 4.芯片组通常分为两个 ...

  9. linux学习心得之vim/Cvim篇

    linux学习心得之vim/Cvim篇 在linux 下,vim 时一种最常见的编辑器,很多linux的发行版就自带了.我的是CentOS 6.3. 基本上Vim共分为3种模式,分别是一般模式,编辑模 ...

  10. linux学习:【第3篇】远程连接及软件安装

    狂神声明 : 文章均为自己的学习笔记 , 转载一定注明出处 ; 编辑不易 , 防君子不防小人~共勉 ! linux学习:[第3篇]远程连接及软件安装 远程连接 xshell , xftp软件官网 : ...

随机推荐

  1. login 模块,re 模块

    标准三流 标准输入流:sys. stdin # input的底层 标准输出流:sys. stdout     # print的底层 标准错误流:sys. stderr      # 异常及loggin ...

  2. 【AMAD】django-rules -- 强大的Django鉴权库,不需要数据库

    动机 简介 个人评分 动机 Django默认的权限原子级别是model级.但是一些时候我们像针对model每条数据库记录都进行权限空,也就是对象级权限控制. 简介 django-rules是一个Dja ...

  3. VM Centos 连不上网或者ping不通问题汇总

    首先检查windows关于VM的服务有没有开启.没有开启的都开起来 通过复制形式建立的虚拟机,注意修改网卡地址.和cfg文件的UUID. 虚拟机ip能正常显示但是windows电脑ping不通虚拟机. ...

  4. Spring 中的几个常用的钩子接口

    1.Aware接口 Awear 这个单词的意思是知道的,所以可以猜想以Awear 结尾的接口意思可以把他知道的东西告诉我们.常用的Awear接口有 ApplicationContextAware和 B ...

  5. Fiddler-打断点(bpu)

    一.断点 1.为什么要打断点? 比如一个购买的金额输入框,输入框前端做了限制大于100,那么我们测试的时候,需要测试小于100的情况下.很显然前端只能输入大于100的.这时我们可以先抓到接口,修改请求 ...

  6. Spring实现构造注入

    Spring通过setter访问器实现对属性的赋值,这种做法称为设值注入:Spring还提供了通过构造方法赋值的能力,称为构造注入.使用设值注入时,Spring通过JavaBean的无参构造方法实例化 ...

  7. UML表示类图和对象图

    类图表示不同的实体(人.事物和数据)如何彼此相关,显示了系统的静态结构.类图可用于表示逻辑类,逻辑类通常就是业务人员所谈及的事物种类,比如摇滚乐队.CD.广播剧,或者贷款.住房抵押.汽车信贷及利率的抽 ...

  8. Java 条件语句 if else

    一个 if 语句包含一个布尔表达式和一条或多条语句. 语法 if 语句的语法如下: if(布尔表达式) { //如果布尔表达式为true将执行的语句 } 如果布尔表达式的值为 true,则执行 if ...

  9. python-day29(正式学习)

    目录 元类 什么是元类 为什么用元类 内置函数exec class创建类 type实现 自定义元类 _ _ call _ _ _ _ new _ _ 自定义元类控制的实例化 属性查找顺序 元类 警告! ...

  10. python_0基础开始_day08

    第八节 1,文件操作 文件操作目的: 持久化,永久存储 (数据库之前 -- 文件操作就是代替数据库) 读 1,找到文件位 2,双击打开 3,进行一些操作 4,关闭文件 open() 打开,通过pyth ...