io网络模型介绍

1.介绍Nginx

  1. Nginx是一个高性能的HTTP和反向代理web服务器

2.常见的Web服务器

  1. httpd
  2. Nginx
  3. Tengine
  4. OpenResty

3.介绍Nginx应用场景

  1. 1.代理
  2. 2.负载均衡
  3. 3.代理缓存 (proxy_cache)
  4. 4.静态资源
  5. 5.动静分离
  6. 6.Https
  7. 冰山模型中的一角 ---> 还有很多个使用场景

4.Nginx 安装 配置 启动

  1. 第一种: 源码安装
  2. 第二种: yum --> 官方仓库 配置容易入手------》推荐使用
  3. 第三种: yum --> epel仓库 配置比较复杂
  4. 1.安装官方仓库源
  5. [root@web01 ~]# cat /etc/yum.repos.d/nginx.repo
  6. [nginx-stable]
  7. name=nginx stable repo
  8. baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
  9. gpgcheck=1
  10. enabled=1
  11. gpgkey=https://nginx.org/keys/nginx_signing.key
  12. 2.使用yum直接安装
  13. [root@web01 ~]# yum install nginx -y
  14. 3.启动nginx
  15. [root@web01 ~]# systemctl restart nginx

5.Nginx 配置 了解

  1. [root@web01 ~]# cat /etc/nginx/nginx.conf
  2. user nginx; # nginx进程的用户身份
  3. worker_processes 1; # nginx的工作进程数量
  4. error_log /var/log/nginx/error.log warn; # 错误日志的路径 [警告级别才会记录]
  5. pid /var/run/nginx.pid; # 进程运行后,会产生一个pid
  6. events { # 事件模型
  7. worker_connections 1024; # 每个work能够支持的连接数
  8. use epoll; # 使用epoll网络模型
  9. }
  10. http { # 接收用户的http请求
  11. include /etc/nginx/mime.types; # 包含所有静态资源的文件
  12. default_type application/octet-stream; # 默认类型 (下载)
  13. 日志相关:
  14. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  15. '$status $body_bytes_sent "$http_referer" '
  16. '"$http_user_agent" "$http_x_forwarded_for"';
  17. access_log /var/log/nginx/access.log main; # 访问日志的路径
  18. #sendfile on;
  19. #tcp_nopush on;
  20. keepalive_timeout 65; #长链接超时时间
  21. #gzip on; #启用压缩功能
  22. #使用Server配置网站, 每个Server{}代表一个网站
  23. server {
  24. listen 80;
  25. server_name test.oldxu.com;
  26. location / { #控制网站访问的路径
  27. root ...;
  28. }
  29. }
  30. include /etc/nginx/conf.d/*.conf; 包含哪些文件
  31. }
  32. PS: Nginx中的http、server、location之间的关系是?
  33. http   标签主要用来解决用户的请求与响应。
  34. server   标签主要用来响应具体的某一个网站。
  35. location   标签主要用于匹配网站具体url路径。
  36. http{} 层下允许有多个Server{},可以有多个网站.
  37. 一个Server{} 下又允许有多个location{} 每个网站的uri路径不同,所以要分别进行匹配.

6.Nginx 搭建 游戏网站

1.注释掉之前的默认网站

  1. [root@web01 html]# cd /etc/nginx/conf.d/
  2. [root@web01 conf.d]# gzip default.conf

2.编写游戏网站Nginx配置文件

  1. [root@web01 conf.d]# cat game.oldxu.com.conf
  2. server {
  3. listen 80; #该网站提供访问的端口
  4. server_name game.oldxu.com; #访问该网站的域名
  5. location / {
  6. root /code;
  7. index index.html;
  8. }
  9. }

3.根据Nginx的配置文件,初始化环境

  1. [root@web01 conf.d]# mkdir /code

4.上传游戏文件源代码

  1. [root@web01 conf.d]# cd /code/
  2. [root@web01 code]# rz html5.zip
  3. [root@web01 code]# unzip html5.zip

5.检测语法

  1. [root@web01 code]# nginx -t
  2. nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  3. nginx: configuration file /etc/nginx/nginx.conf test is successful

6.重载服务

  1. [root@web01 code]# systemctl restart nginx

7.配置域名解析 hosts

  1. PC机:C:\Windows\System32\drivers\etc

8.Nginx访问的整体流程

  1. http:// game.oldxu.com / game/yibihua/index.html
  2. 请求的uri: /game/yibihua/index.html
  3. 真实映射位置: /code/game/yibihua/index.html

9.Nginx 搭建 多个游戏网站 ---> 虚拟主机

虚拟主机: 在一台服务器上运行多套网站

Nginx配置虚拟主机有如下三种方式:
  1. 方式一、基于主机多IP方式 10.0.0.7 172.16.1.7
  2. 方式二、基于端口的配置方式 80 81 82 83
  3. 方式三、基于名称方式(多域名方式) test1 test2 test3 <---推荐
  • 方式一、基于主机多IP方式
  1. [root@web01 conf.d]# cat ip_eth0.conf
  2. server {
  3. listen 10.0.0.7:80;
  4. location / {
  5. root /ip1;
  6. index index.html;
  7. }
  8. }
  9. server {
  10. listen 172.16.1.7:80;
  11. location / {
  12. root /ip2;
  13. index index.html;
  14. }
  15. }
  16. [root@web01 conf.d]# mkdir /ip1 /ip2
  17. [root@web01 conf.d]# echo "10...." > /ip1/index.html
  18. [root@web01 conf.d]# echo "172...." > /ip2/index.html
  19. [root@web01 conf.d]# systemctl restart nginx
  20. 测试访问
  21. [root@web01 ~]# curl http://10.0.0.7
  22. 10....
  23. [root@web01 ~]# curl http://172.16.1.7
  24. 172....
  • 方式二、基于端口的配置方式 81 82 83

    公司内部有多套系统,希望部署在一台服务器上, 而内网又没有域名.

    所以,我们可以通过相同IP,不同的端口,访问不同的网站页面.
  1. [root@web01 conf.d]# cat port.conf
  2. server {
  3. listen 81;
  4. location / {
  5. root /81;
  6. index index.html;
  7. }
  8. }
  9. server {
  10. listen 82;
  11. location / {
  12. root /82;
  13. index index.html;
  14. }
  15. }
  16. server {
  17. listen 83;
  18. location / {
  19. root /83;
  20. index index.html;
  21. }
  22. }
  23. [root@web01 conf.d]# mkdir /81 /82 /83
  24. [root@web01 conf.d]# echo "81" > /81/index.html
  25. [root@web01 conf.d]# echo "82" > /82/index.html
  26. [root@web01 conf.d]# echo "83" > /83/index.html
  • 方式三、三个网站运行在同一台服务器,只需要通过不同的域名来实现访问:
  1. 1. game.cyw.com
  2. [root@web01 code]# cat /etc/nginx/conf.d/game.cyw.com.conf
  3. server {
  4. listen 80;
  5. server_name game.cyw.com;
  6. location / {
  7. root /code;
  8. index index.html;
  9. }
  10. }
  11. 2. game2.yinwu.com
  12. [root@web01 code2]# cat /etc/nginx/conf.d/game2.yinwu.com.conf
  13. server {
  14. listen 80;
  15. server_name game2.yinwu.com;
  16. location / {
  17. root /code2/TangMen;
  18. index index.html;
  19. }
  20. }
  21. 3. game3.yinwu.com
  22. [root@web01 code3]# cat /etc/nginx/conf.d/game3.yinwu.com.conf
  23. server {
  24. listen 80;
  25. server_name game3.yinwu.com;
  26. location / {
  27. root /code3/Mota;
  28. index index.html;
  29. }
  30. }

8.Nginx基本概述的更多相关文章

  1. Nginx指令概述

    指令概述 配置指令是一个字符串,可以用单引号或者双引号括起来,也可以不括.但是如果配置指令包含空格,一定要引起来. 指令参数 指令的参数使用一个或者多个空格或者TAB字符与指令分开.指令的参数有一个或 ...

  2. Nginx的概述和配置

    一.Nginx概述 1.1Nginx的特点 (1)一款高性能.轻量级web服务 稳定性高 系统资源消耗低高 对HTTP并发连接的处理能力 (2)单台物理服务器可支持30000~50000个并发请求 1 ...

  3. Nginx教程/概述

    Nginx(发音同engine x)是一个异步框架的 Web服务器,也可以用作反向代理,负载平衡器 和 HTTP缓存.该软件由 Igor Sysoev 创建,并于2004年首次公开发布.同名公司成立于 ...

  4. nginx基础概述

    为什么选择nginx     nginx非常轻量     互联网公司都选择nginx nginx技术成熟,具备的功能时企业最常用使用而且最需要的 适合当前主流架构趋势,微服务.云架构.中间层 统一技术 ...

  5. nginx基本概述

    上级回顾: 1.NFS 2.Sersync 3.SSH 1.ssh使用两种登录服务器的方式,哪两种? 密码 用户名 + 密码 秘钥 用户名 + 秘钥(私钥) 公钥加密 私钥解密 2.大家常说的 塞ke ...

  6. nginx系列 2 概述

    一. nginx功能概述 nginx 提供的基本功能服务归纳为:基本HTTP服务.高级HTTTP服务.邮件代理服务.TCP/UDP 代理服务等四大类. (1) Nginx提供基本HTTP服务,可以作为 ...

  7. Nginx学习笔记六Nginx的模块开发

    1.Nginx配置文件主要组成:main(全局配置)这部分的指令将影响其他所有部分.server(虚拟主机配置)这部分指令主要用于指定虚拟主机域名,IP和端口.upstream(主要为反向代理,负载均 ...

  8. nginx 官方文档翻译

    nginx(发音为"engine x")是一个由俄罗斯软件工程师Igor Sysoev编写的免费开源Web服务器.自2004年公开发布以来,nginx专注于高性能,高并发性和低内存 ...

  9. Nginx 模块开发

    Nginx 模块概述 Nginx 模块有三种角色: 处理请求并产生输出的 Handler 模块 : 处理由  Handler  产生的输出的 Filter (滤波器)模块: 当出现多个后台 服务器时, ...

随机推荐

  1. Linux服务器MySQL安装

    Linux服务器MySQL安装 1. MySQL官网下载如图: 2. 安装MySQL [root@iZ2zebb0428roermd00462Z /]# rpm -ivh https://dev.my ...

  2. 无法解析的外部符号,该符号在xxx函数中被引用

    无法解析的外部符号.........,该符号在函数.........被引用 在我们敲代码的过程中,我们偶尔会遇到这个问题,这个问题大多数都是因为你自己的程序有问题,而不是缺少相应的库文件.话不多说,直 ...

  3. C#基础知识总结(三)--反射

    如何在C#.NET开发中使用反射. 首先,我新建一个普通的类库项目.在该项目的测试类中,定义好 属性.静态方法.实例方法.无参方法等... 代码如下: using System; using Syst ...

  4. [VB.NET Tips]字符串分隔

    在实际应用中,很多场景下都需要分隔字符串,如解析CSV文件等. 一般我们使用split方法来按照指定的分隔符来进行分隔字符串获得一个数组. Split方法的签名是: Split(ParamArray ...

  5. (七十三)c#Winform自定义控件-资源加载窗体

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  6. 使用命令行创建maven web项目

    一,前言 遇到了一个非常简单的maven命令: 总的来说,这是一个用maven创建一个jersey快速开始项目的maven命令. 这次不妨使用maven命令来构建项目,看体验如何. 在文章idea m ...

  7. [系列] go-gin-api 路由中间件 - Jaeger 链路追踪(六)

    [DOC] 概述 首先同步下项目概况: 上篇文章分享了,路由中间件 - Jaeger 链路追踪(理论篇),这篇文章咱们接着分享:路由中间件 - Jaeger 链路追踪(实战篇). 这篇文章,确实让大家 ...

  8. selenium-04-验证码问题

    对于web应用来说,大部分的系统在用户登录时都要求用户输入验证码,验证码的类型的很多,有字母数字的,有汉字的,甚至还要用户输入一条算术题的答案的,对于系统来说使用验证码可以有效果的防止采用机器猜测方法 ...

  9. Mysql 笔记二

    Mysql 笔记二 Mysql 笔记二 Table of Contents 1. 前言 2. Master Thread 工作方式 2.1. 主循环(loop) 2.2. 后台循(backgroup ...

  10. 2019-ccpc秦皇岛现场赛

    https://www.cnblogs.com/31415926535x/p/11625462.html 昨天和队友模拟了下今年秦皇岛的区域赛,,,(我全程在演 题目链接 D - Decimal 签到 ...