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 (滤波器)模块: 当出现多个后台 服务器时, ...
随机推荐
- FlutterGo 后端知识点提炼:midway+Typescript+mysql(sequelize)
前言 关于 FlutterGo 或许不用太多介绍了. 如果有第一次听说的小伙伴,可以移步FlutterGo官网查看下简单介绍. FlutterGo 在这次迭代中有了不少的更新,笔者在此次的更新中,负责 ...
- 04.Django基础四之模板系统
一 语法 模板渲染的官方文档 关于模板渲染你只需要记两种特殊符号(语法): {{ }}和 {% %} 变量相关的用{{}},逻辑相关的用{%%}. 二 变量 在Django的模板语言中按此语法使用:{ ...
- Java 集合转换(数组、List、Set、Map相互转换)
package com.example.test; import java.util.ArrayList; import java.util.Arrays; import java.util.Hash ...
- [Linux] Vmware 15安装CentOs后显示网络不可用
转载自:https://blog.csdn.net/chenjin_chenjin/article/details/83617186 在虚拟机上安装好centos7后,ping www.baidu.c ...
- java枚举的应用
最近的项目中,看前辈们用到的枚举比较多,由于自己之前对枚举这种类型不是很了解,遂花费心机看了下,整理记录下. 1.枚举常量 系统中定义的状态字段,用的比较多: public enum orderTyp ...
- vmware配置静态ip
wmware安装后,默认是动态ip地址. 在测试环境搭建虚拟机后,都需要使用静态ip地址.但是配置固定静态ip地址后,虚拟机总是不能上网和访问网站域名. 原来问题出在配置固定ip后配置的的网关和域名解 ...
- lcx端口转发
目录 0x01 正向端口转发 0x02 反向端口转发 0x03 msf正向shell 0x04 msf反向shell 注: 边界机器 win08 192.168.222.175 内网机器 win7 1 ...
- 常用HBase操作
HBase是一个分布式.面向列的数据库,可以用来存储非结构化和半结构化的松散数据,具有高可靠.高性能.面向列.可伸缩的特性.通过行键(RowKey).列族(ColumnFamily).列(Column ...
- CDH集群的时间同步--简要配置要求
每个节点执行ntpstat 和 timedatectl 都显示同步并且时间相同,那么CDH才能正常使用.每次ntp服务同步到外部授时中心都要一段时间(5~10分钟),只有当NTP server(nod ...
- Spring 梳理-webApplicationContext 与servletContext
1.WebApplicationContext的研究 ApplicationContext是spring的核心,Context通常解释为上下文环境,用“容器”来表述更容易理解一些,Applicatio ...