8.Nginx基本概述
io网络模型介绍
1.介绍Nginx
Nginx是一个高性能的HTTP和反向代理web服务器
2.常见的Web服务器
httpd
Nginx
Tengine
OpenResty
3.介绍Nginx应用场景
1.代理
2.负载均衡
3.代理缓存 (proxy_cache)
4.静态资源
5.动静分离
6.Https
冰山模型中的一角 ---> 还有很多个使用场景
4.Nginx 安装 配置 启动
第一种: 源码安装
第二种: yum --> 官方仓库 新 配置容易入手------》推荐使用
第三种: yum --> epel仓库 旧 配置比较复杂
1.安装官方仓库源
[root@web01 ~]# cat /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
2.使用yum直接安装
[root@web01 ~]# yum install nginx -y
3.启动nginx
[root@web01 ~]# systemctl restart nginx
5.Nginx 配置 了解
[root@web01 ~]# cat /etc/nginx/nginx.conf
user nginx; # nginx进程的用户身份
worker_processes 1; # nginx的工作进程数量
error_log /var/log/nginx/error.log warn; # 错误日志的路径 [警告级别才会记录]
pid /var/run/nginx.pid; # 进程运行后,会产生一个pid
events { # 事件模型
worker_connections 1024; # 每个work能够支持的连接数
use epoll; # 使用epoll网络模型
}
http { # 接收用户的http请求
include /etc/nginx/mime.types; # 包含所有静态资源的文件
default_type application/octet-stream; # 默认类型 (下载)
日志相关:
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main; # 访问日志的路径
#sendfile on;
#tcp_nopush on;
keepalive_timeout 65; #长链接超时时间
#gzip on; #启用压缩功能
#使用Server配置网站, 每个Server{}代表一个网站
server {
listen 80;
server_name test.oldxu.com;
location / { #控制网站访问的路径
root ...;
}
}
include /etc/nginx/conf.d/*.conf; 包含哪些文件
}
PS: Nginx中的http、server、location之间的关系是?
http 标签主要用来解决用户的请求与响应。
server 标签主要用来响应具体的某一个网站。
location 标签主要用于匹配网站具体url路径。
http{} 层下允许有多个Server{},可以有多个网站.
一个Server{} 下又允许有多个location{} 每个网站的uri路径不同,所以要分别进行匹配.
6.Nginx 搭建 游戏网站
1.注释掉之前的默认网站
[root@web01 html]# cd /etc/nginx/conf.d/
[root@web01 conf.d]# gzip default.conf
2.编写游戏网站Nginx配置文件
[root@web01 conf.d]# cat game.oldxu.com.conf
server {
listen 80; #该网站提供访问的端口
server_name game.oldxu.com; #访问该网站的域名
location / {
root /code;
index index.html;
}
}
3.根据Nginx的配置文件,初始化环境
[root@web01 conf.d]# mkdir /code
4.上传游戏文件源代码
[root@web01 conf.d]# cd /code/
[root@web01 code]# rz html5.zip
[root@web01 code]# unzip html5.zip
5.检测语法
[root@web01 code]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
6.重载服务
[root@web01 code]# systemctl restart nginx
7.配置域名解析 hosts
PC机:C:\Windows\System32\drivers\etc
8.Nginx访问的整体流程
http:// game.oldxu.com / game/yibihua/index.html
请求的uri: /game/yibihua/index.html
真实映射位置: /code/game/yibihua/index.html
9.Nginx 搭建 多个游戏网站 ---> 虚拟主机
虚拟主机: 在一台服务器上运行多套网站
Nginx配置虚拟主机有如下三种方式:
方式一、基于主机多IP方式 10.0.0.7 172.16.1.7
方式二、基于端口的配置方式 80 81 82 83
方式三、基于名称方式(多域名方式) test1 test2 test3 <---推荐
- 方式一、基于主机多IP方式
[root@web01 conf.d]# cat ip_eth0.conf
server {
listen 10.0.0.7:80;
location / {
root /ip1;
index index.html;
}
}
server {
listen 172.16.1.7:80;
location / {
root /ip2;
index index.html;
}
}
[root@web01 conf.d]# mkdir /ip1 /ip2
[root@web01 conf.d]# echo "10...." > /ip1/index.html
[root@web01 conf.d]# echo "172...." > /ip2/index.html
[root@web01 conf.d]# systemctl restart nginx
测试访问
[root@web01 ~]# curl http://10.0.0.7
10....
[root@web01 ~]# curl http://172.16.1.7
172....
- 方式二、基于端口的配置方式 81 82 83
公司内部有多套系统,希望部署在一台服务器上, 而内网又没有域名.
所以,我们可以通过相同IP,不同的端口,访问不同的网站页面.
[root@web01 conf.d]# cat port.conf
server {
listen 81;
location / {
root /81;
index index.html;
}
}
server {
listen 82;
location / {
root /82;
index index.html;
}
}
server {
listen 83;
location / {
root /83;
index index.html;
}
}
[root@web01 conf.d]# mkdir /81 /82 /83
[root@web01 conf.d]# echo "81" > /81/index.html
[root@web01 conf.d]# echo "82" > /82/index.html
[root@web01 conf.d]# echo "83" > /83/index.html
- 方式三、三个网站运行在同一台服务器,只需要通过不同的域名来实现访问:
1. game.cyw.com
[root@web01 code]# cat /etc/nginx/conf.d/game.cyw.com.conf
server {
listen 80;
server_name game.cyw.com;
location / {
root /code;
index index.html;
}
}
2. game2.yinwu.com
[root@web01 code2]# cat /etc/nginx/conf.d/game2.yinwu.com.conf
server {
listen 80;
server_name game2.yinwu.com;
location / {
root /code2/TangMen;
index index.html;
}
}
3. game3.yinwu.com
[root@web01 code3]# cat /etc/nginx/conf.d/game3.yinwu.com.conf
server {
listen 80;
server_name game3.yinwu.com;
location / {
root /code3/Mota;
index index.html;
}
}
8.Nginx基本概述的更多相关文章
- Nginx指令概述
指令概述 配置指令是一个字符串,可以用单引号或者双引号括起来,也可以不括.但是如果配置指令包含空格,一定要引起来. 指令参数 指令的参数使用一个或者多个空格或者TAB字符与指令分开.指令的参数有一个或 ...
- Nginx的概述和配置
一.Nginx概述 1.1Nginx的特点 (1)一款高性能.轻量级web服务 稳定性高 系统资源消耗低高 对HTTP并发连接的处理能力 (2)单台物理服务器可支持30000~50000个并发请求 1 ...
- Nginx教程/概述
Nginx(发音同engine x)是一个异步框架的 Web服务器,也可以用作反向代理,负载平衡器 和 HTTP缓存.该软件由 Igor Sysoev 创建,并于2004年首次公开发布.同名公司成立于 ...
- nginx基础概述
为什么选择nginx nginx非常轻量 互联网公司都选择nginx nginx技术成熟,具备的功能时企业最常用使用而且最需要的 适合当前主流架构趋势,微服务.云架构.中间层 统一技术 ...
- nginx基本概述
上级回顾: 1.NFS 2.Sersync 3.SSH 1.ssh使用两种登录服务器的方式,哪两种? 密码 用户名 + 密码 秘钥 用户名 + 秘钥(私钥) 公钥加密 私钥解密 2.大家常说的 塞ke ...
- nginx系列 2 概述
一. nginx功能概述 nginx 提供的基本功能服务归纳为:基本HTTP服务.高级HTTTP服务.邮件代理服务.TCP/UDP 代理服务等四大类. (1) Nginx提供基本HTTP服务,可以作为 ...
- Nginx学习笔记六Nginx的模块开发
1.Nginx配置文件主要组成:main(全局配置)这部分的指令将影响其他所有部分.server(虚拟主机配置)这部分指令主要用于指定虚拟主机域名,IP和端口.upstream(主要为反向代理,负载均 ...
- nginx 官方文档翻译
nginx(发音为"engine x")是一个由俄罗斯软件工程师Igor Sysoev编写的免费开源Web服务器.自2004年公开发布以来,nginx专注于高性能,高并发性和低内存 ...
- Nginx 模块开发
Nginx 模块概述 Nginx 模块有三种角色: 处理请求并产生输出的 Handler 模块 : 处理由 Handler 产生的输出的 Filter (滤波器)模块: 当出现多个后台 服务器时, ...
随机推荐
- 创建型模式总结(2.x)
顾名思义,创建型模式的聚焦点在如何创建对象能够将对象的创建与使用最大化的分离从而降低系统的耦合度. 创建型模式可分为: 单例模式:一个类只能有一个实例对象 工厂模式: 简单工厂模式:聚焦单个产品种类的 ...
- 详细的App推广前的准备工作
App开发完成后,推广App自然就成为下一步工作的重点.兵马未动,粮草先行,这里为大家整理了一份App推广前需要准备一些事项,希望能给正在准备开展App推广的小伙伴们一些帮助. 众所周知,App推广的 ...
- python 切片步长
python切片 切片:list变量[值下标:结束值下标] 什么意思呢? 就是获取 list中 下标从定义的位置开始获取数据到 自定义的下标位置结束, 但是切片有个规矩就是顾头不顾尾, 举个例子 ...
- 小白专场-FileTransfer-c语言实现
目录 一.集合的简化表示 二.题意理解 三.程序框架搭建 3.1 Input_connection 3.2 Check_connection 3.3 Check_network 四.pta测试 五.按 ...
- java、if判断和循环
一.选择.循环语法 选择 if if(表达式)语句A: 如果表达式的值是真的,就会执行语句A,否则不执行 ...
- 2018年蓝桥杯ava b组第一题
第一题.标题:第几天 2000年的1月1日,是那一年的第1天.那么,2000年的5月4日,是那一年的第几天? 注意:需要提交的是一个整数,不要填写任何多余内容 如果问我怎么做的,我就是看日历做的,看了 ...
- Java 学习笔记之 异常法停止线程
异常法停止线程: public class RealInterruptThread extends Thread { @Override public void run() { try { for ( ...
- Java 学习笔记之 线程interrupted方法
线程interrupted方法: interrupted()是Thread类的方法,用来测试当前线程是否已经中断. public class InterruptThread extends Threa ...
- QR 码详解(上)
关于二维码,我查了下资料,现在基本都在用日本的 QR 码,PDF417以及汉信码日常基本看不到.原因在于各方面来说,的确是 QR 码最为优秀.所以我准备写一篇介绍 QR 码的文章,如果是写书,可能不方 ...
- 从零开始的 phpstorm+wamp 组合下的debug环境搭建(纯小白向)
本文主要是为了帮自己记住每次重装系统后需要干点啥,如果能帮到你,烦请给个好评 环境说明: 1. windows10 64bit 2. wampservers 3.0.6(x86) apache2.4. ...