第九章 nginx基础之搭建小游戏
一、nginx部署
1.epel源安装
[root@web01 ~]# yum install -y nginx
2.官方源安装
1.配置官方源
[root@web02 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
2.安装依赖
[root@web02 ~]# yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
3.安装nginx
[root@web02 ~]# yum install -y nginx
4.创建用户
[root@web02 ~]# groupadd www -g 666
[root@web02 ~]# useradd www -u 666 -g 666
5.修改nginx启动用户
[root@web02 ~]# vim /etc/nginx/nginx.conf
user www;
6.启动服务
[root@web02 ~]# systemctl restart nginx
7.验证启动
[root@web02 ~]# ps -ef | grep nginx
3.源码包安装
1.安装依赖
[root@web03 ~]# yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
2.下载或上传源码包
[root@web03 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
#或者
[root@web03 ~]# rz nginx-1.18.0.tar.gz
3.解压
[root@web03 ~]# tar xf nginx-1.18.0.tar.gz
4.创建用户
[root@web03 ~]# groupadd www -g 666
[root@web03 ~]# useradd www -u 666 -g 666
5.生成编译文件
[root@web03 ~]# cd nginx-1.18.0/
[root@web03 ~/nginx-1.18.0]# ./configure --prefix=/usr/local/nginx-1.18.0 --user=www --group=www --with-http_addition_module --with-http_auth_request_module --without-http_gzip_module
6.编译安装
[root@web03 ~/nginx-1.18.0]# make && make install
7.配置system管理
[root@web03 ~]# vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
8.做软连接
[root@web03 ~]# ln -s /usr/local/nginx-1.18.0 /usr/local/nginx
#配置环境变量
[root@web03 ~]# cat /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin/:$PATH
#软连接的作用:
1)配置环境变量可以不加版本号
2)配置system启动可以不加版本号
3)升级直接切换软连接的链接文件即可
9.启动
[root@web03 ~]# systemctl daemon-reload
[root@web03 ~]# systemctl start nginx
#配置开机自启
[root@web03 ~]# systemctl enable nginx
4.nginx升级
1.下载新版本的包
[root@web03 ~]# wget http://nginx.org/download/nginx-1.19.2.tar.gz
2.解压
[root@web03 ~]# tar xf nginx-1.19.2.tar.gz
3.生成编译安装
[root@web03 ~]# cd nginx-1.19.2/
[root@web03 nginx-1.19.2]# ./configure --prefix=/usr/local/nginx-1.19.2 --user=www --group=www --with-http_addition_module --with-http_auth_request_module --without-http_gzip_module
[root@web03 nginx-1.19.2]# make && make install
4.替换配置文件
[root@web03 /usr/local]# cp nginx-1.18.0/conf/nginx.conf nginx-1.19.2/conf/
cp: overwrite ‘nginx-1.19.2/conf/nginx.conf’? y
5.重启nginx
[root@web03 /usr/local]# systemctl restart nginx
二、nginx相关配置文件
为了让大家更清晰的了解Nginx软件的全貌,可使用rpm -ql nginx查看整体的目录结构及对应的功能,
如下表格整理了Nginx比较重要的配置文件
1.nginx主配置文件
路径 | 类型 | 作用 |
---|---|---|
/etc/nginx/nginx.conf | 配置文件 | nginx主配置文件 |
/etc/nginx/conf.d/default.conf | 配置文件 | 默认网站配置文件 |
2.Nginx代理相关参数文件
路径 | 类型 | 作用 |
---|---|---|
/etc/nginx/fastcgi_params | 配置文件 | Fastcgi代理配置文件(php) |
/etc/nginx/scgi_params | 配置文件 | scgi代理配置文件 |
/etc/nginx/uwsgi_params | 配置文件 | uwsgi代理配置文件(python) |
3.Nginx编码相关配置文件
路径 | 类型 | 作用 |
---|---|---|
/etc/nginx/win-utf | 配置文件 | Nginx编码转换映射文件 |
/etc/nginx/koi-utf | 配置文件 | Nginx编码转换映射文件 |
/etc/nginx/koi-win | 配置文件 | Nginx编码转换映射文件 |
/etc/nginx/mime.types | 配置文件 | Content-Type与扩展名,nginx支持的数据类型 |
4.Nginx管理相关命令
路径 | 类型 | 作用 |
---|---|---|
/usr/sbin/nginx | 命令 | Nginx命令行管理终端工具 |
/usr/sbin/nginx-debug | 命令 | Nginx命令行与终端调试工具 |
5.Nginx日志相关目录与文件
路径 | 类型 | 作用 |
---|---|---|
/var/log/nginx | 目录 | Nginx默认存放日志目录 |
/etc/logrotate.d/nginx | 配置文件 | Nginx默认的日志切割 |
三、nginx主配置文件
1.nginx主配置文件概述
Nginx主配置文件/etc/nginx/nginx.conf是一个纯文本类型的文件,整个配置文件是以区块的形式组织的。
一般,每个区块以一对大括号{}来表示开始与结束。
Nginx主配置文件整体分为三块进行学习,分别是CoreModule(核心模块),EventModule(事件驱动模块),HttpCoreModule(http内核模块)
2.nginx主配置文件详解
[root@web02 ~]# cat /etc/nginx/nginx.conf
#---------------------------核心模块------------------------------
#启动用户
user www;
#工作进程数
worker_processes 1;
#错误日志 debug/info/notice/warn/error/emeor
error_log /var/log/nginx/error.log warn;
#pid文件
pid /var/run/nginx.pid;
#---------------------------事件驱动模块---------------------------
#事件
events {
#工作进程的连接数
worker_connections 1024;
}
#------------------------------http内核模块------------------------
#网站配置
http {
#nginx包含的文件类型
include /etc/nginx/mime.types;
#当遇到nginx不识别的文件就会下载
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;
#包含的配置文件
include /etc/nginx/conf.d/*.conf;
server {
#服务监听端口
listen 80;
#域名
server_name localhost;
#字符集
charset koi8-r;
#请求的地址
location / {
#站点目录,当访问/的时候跳转目录
root /usr/share/nginx/html;
#默认访问页面
index index.html index.htm;
}
}
四、nginx搭建小游戏
1.需求
1.使用两种方式安装方式安装nginx
2.搭建一个和多个小游戏页面
2.环境准备
主机 | 角色 | IP |
---|---|---|
web01 | 使用官方源安装nginx搭建多个小游戏 | 10.0.0.7 |
web02 | 使用源码安装nginx搭建一个游戏页面 | 10.0.0.8 |
3.web01搭建游戏页面
1.关闭防火墙
[root@web01 ~]# systemctl stop firewalld
[root@web01 ~]# systemctl disable firewalld
2.关闭selinux
[root@web01 ~]# setenforce 0
[root@web01 ~]# vim /etc/selinux/config
SELINUX=disabled
3.配置官方源
[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
4.安装依赖
[root@web01 ~]# yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
5.安装nginx
[root@web01 ~]# yum -y install nginx
6.启动服务设置开机自启并验证服务
[root@web01 ~]# systemctl start nginx
[root@web01 ~]# systemctl enable nginx
[root@web01 ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 6125/rpcbind
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 8840/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 7108/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7249/master
tcp6 0 0 :::111 :::* LISTEN 6125/rpcbind
tcp6 0 0 :::22 :::* LISTEN 7108/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7249/master
8.修改nginx主配置文件
[root@web01 ~]# vim /etc/nginx/nginx.conf
user www;
9.创建统一用户
[root@web01 ~]# groupadd www -g 666
[root@web01 ~]# useradd www -u 666 -g 666
10.修改nginx站点配置文件
[root@web01 /code]# vim /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name www.oldboy.com;
location / {
root /code/malio;
index index.html index.htm;
}
}
server {
listen 81;
server_name www.jh.com;
location / {
root /code/tank;
index index.html index.htm;
}
}
server {
listen 82;
server_name www.jindada.com;
location / {
root /code/tuixiangzi;
index index.html index.htm;
}
}
11.创建目录
[root@web01 ~]# mkdir /code
12.上传游戏压缩包
[root@web01 ~]# rz -E
rz waiting to receive.
[root@web01 ~]# ll
total 2852
-rw-r--r-- 1 root root 148142 Jun 5 00:06 html5-mario.zip
-rw-r--r-- 1 root root 167427 Jun 5 00:00 tank.zip
-rw-r--r-- 1 root root 64723 Jun 4 18:40 tuixiangzi.zip
-rw-r--r-- 1 root root 2525626 Jun 4 18:06 weijingzhanzheng.zip
13。解压到指定目录,并重命名
[root@web01 ~]# unzip /root/html5-mario.zip -d /code
[root@web01 ~]# mv html5-mario/ ./malio
[root@web01 ~]# unzip /root/tank.zip -d /code/
[root@web01 ~]# mv Battle_City/ ./tank
[root@web01 ~]# unzip /root/tuixiangzi.zip -d /code/
[root@web01 ~]# mv HTML5\ canvas小人推箱子小游戏/ tuixiangzi
14.修改权限
[root@web01 ~]# chown -R www:www /code/
15.检查nginx,重启服务
[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
[root@web01 /code]# systemctl restart nginx
16.修改windows下hosts文件
C:\Windows\System32\drivers\etc\hosts
10.0.0.7 www.jh.com
10.0.0.7 www.oldboy.com
10.0.0.7 www.jindada.com
4.web02搭建游戏页面
1.关闭防火墙
[root@web02 ~]# systemctl stop firewalld
[root@web02 ~]# systemctl disable firewalld
2.关闭selinux
[root@web02 ~]# setenforce 0
[root@web02 ~]# vim /etc/selinux/config
SELINUX=disabled
3.安装依赖
[root@web02 ~]# yum install -y gcc gcc-c++ autoconf pcre pcre-devel make automake wget httpd-tools vim tree
4.下载或上传源码包
[root@web02 ~]# wget http://nginx.org/download/nginx-1.18.0.tar.gz
--2020-08-20 20:58:55-- http://nginx.org/download/nginx-1.18.0.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1039530 (1015K) [application/octet-stream]
Saving to: ‘nginx-1.18.0.tar.gz’
100%[==========================>] 1,039,530 499KB/s in 2.0s
2020-08-20 20:58:57 (499 KB/s) - ‘nginx-1.18.0.tar.gz’ saved [1039530/1039530]
#或者
[root@web03 ~]# rz nginx-1.18.0.tar.gz
5.解压
[root@web02 ~]# tar xf nginx-1.18.0.tar.gz
6.创建用户
[root@web02 ~]# groupadd www -g 666
[root@web02 ~]# useradd www -u 666 -g 666
7.生成编译文件
[root@web02 ~]# cd nginx-1.18.0/
[root@web02 ~/nginx-1.18.0]# ./configure --prefix=/usr/local/nginx-1.18.0 --user=www --group=www --with-http_addition_module --with-http_auth_request_module --without-http_gzip_module
8.编译安装
[root@web02 ~/nginx-1.18.0]# make && make install
9.配置system管理
[root@web02 ~]# vim /etc/systemd/system/nginx.service
[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop
[Install]
WantedBy=multi-user.target
10.做软连接
[root@web02 ~]# ln -s /usr/local/nginx-1.18.0 /usr/local/nginx
12.配置环境变量
[root@web02 ~]# vim /etc/profile.d/nginx.sh
export PATH=/usr/local/nginx/sbin/:$PATH
13.启动nginx服务
[root@web03 ~]# systemctl daemon-reload
[root@web03 ~]# systemctl start nginx
#配置开机自启
[root@web03 ~]# systemctl enable nginx
14.修改nginx主配置文件
[root@web02 ~]# vim /usr/local/nginx-1.18.0/conf/nginx.conf
user www;
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
root /code/tuixiangzi;
index index.html index.htm;
}
14.创建目录
[root@web02 ~]# mkdir /code
15.上传游戏包并解压到指定目录,重命名为tuixiangzi
[root@web02 ~]# rz -bye
[root@web02 ~]# ll
total 1088
-rw-r--r-- 1 root root 64723 2020-06-04 18:40 tuixiangzi.zip
[root@web02 ~]# unzip tuixiangzi.zip -d /code/
[root@web02 ~]# mv /code/HTML5\ canvas小人推箱子小游戏/ /code/tuixiangzi
16.修改权限
[root@web02 ~]# chown -R www:www /code/
17.验证服务重启服务
[root@web02 ~]# nginx -t
nginx: the configuration file /usr/local/nginx-1.18.0/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx-1.18.0/conf/nginx.conf test is successful
[root@web02 ~]# systemctl restart nginx
5.测试
1.web01打开浏览器使用域名正常登陆游戏页面
wwwww.jh.com:81 #正常显示
www.oldboy.com #正常显示
www.jindada.cow:82 #正常显示
2.web02打开浏览器使用ip正常登陆游戏页面
10.0.0.8 #正常显示
第九章 nginx基础之搭建小游戏的更多相关文章
- Nginx基础环境搭建
1.下载docker toolbox https://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ 2.选择好安装目录 一路nex ...
- Vue.js-09:第九章 - 组件基础再探(data、props)
一.前言 在上一章的学习中,我们学习了 Vue 中组件的基础知识,知道了什么是组件,以及如何创建一个全局/局部组件.不知道你是否记得,在上一章中,我们提到组件是一个可以复用的 Vue 实例,它与 Vu ...
- 青瓷qici - H5小游戏 抽奖机 “one-arm bandit”
写在前面 本文实现一个简单的抽奖效果,使用青瓷qici引擎,其中应用了Tween动画,粒子系统,遮罩,UI界面布局,项目设置,发布等功能呢. 目前开发采用1.0.7版本,后续如果界面有所变化请参考这个 ...
- Objective-C 基础教程第九章,内存管理
目录 Object-C 基础教程第九章,内存管理 前言: 对象生命周期 引用计数 RetainCount1项目例子 对象所有权 访问方法中的保留和释放 自动释放 所有对象放入池中 自动释放池的销毁时间 ...
- 通过游戏学python 3.6 第一季 第九章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁定账号--锁定次数--菜单功能'menufile
通过游戏学python 3.6 第一季 第九章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁 ...
- 看一眼就学会的 HTML 小游戏搭建!
本文作者:CODING 用户 - xfly 身边经常会有小伙伴问我有没有办法不买服务器也能上线自己的个人项目,比如不少同学都非常喜欢搭建一个属于自己的博客站点或者小游戏等. 目前相对比较简便的且不花自 ...
- <自动化测试方案_9>第九章、持续集成平台搭建
第九章.持续集成平台搭建 (一)什么是持续集成 参考文章地址:https://blog.csdn.net/qq_32261399/article/details/76651376 敏捷软件开发(英语: ...
- iOS 基础入门--Bull' Eye 小游戏
说明 Bull's Eye小游戏是http://www.raywenderlich.com/store/ios-apprentice里非常酷的入门demo 跟着该教程一步步做下来便有了 ...
- Wordpress搭建社交型小游戏网站10大步骤
http://www.aliyun.com/zixun/content/2_8_196141.html ———————————————————————————————————————————————— ...
随机推荐
- Ruby探微初步
我的导师,曾经对我说过,常规编程语言大抵不过顺序.条件.循环 接下来以Ruby为例,简单说说 控制语句 控制语句能让程序在某种条件下,改变执行顺序,或者只执行某一部分. 控制语句的分类 控制语句大致可 ...
- Linux实战(1):装机一键设置脚本-初级版
#!/bin/bash #此脚本作用是装完centos后所执行的一系列设置,基本是必须设置的操作,主要分为几大功能:修改yum源,安装ifconfig,安装ping,修改selinux配置 #第一部分 ...
- 熟悉ifos项目的记录吧
1.首页关联的:在 default-navigation-model.xml里 2.输入框改成下拉列框 第一步,找到需要修改的view的包,新建一个view obj 第二步,在query里写上需要找的 ...
- 骚操作:不重启 JVM,如何替换掉已经加载的类?
Java对象行为 java.lang.instrument.Instrumentation 直接操作字节码 BTrace Arthas 三生万物 在遥远的希艾斯星球爪哇国塞沃城中,两名年轻的程序员正在 ...
- 秋天的第一份“干货” I Referer 防盗链,为什么少了个字母 R?
Referer 为什么叫 Referer?它代表什么意思?在诸多防盗链竞争中它有什么优势? 今天,在聊 Referer 防盗链之前,先来聊聊我们在现实生活中常常碰到的推荐人(Referrer)信息. ...
- tornado-简介和原理
tornado-设计初衷 1. 追求小而精 2. epoll IO多路复用和协程 3. 支持WebSocket 4. 单线程程序(GIL限制,本身某种意义上不启动多进程就是单线程程序) # Pytho ...
- KEIL查看ARM-Cortex M架构soc的内核寄存器之 MSP
参考下图stm32l475的参考手册: MSP指向地址基地址为0x20000000的内存处.参考STM32L475的memory map可知MSP指向的是SRAM的一块地址.并且由上面的编译信息 ...
- 【网络协议】TCP/IP:数据链路层
物理层负责把计算机中的0.1数字信号转换为具体传输媒介的物理信号(电压的高低.电波的强弱.光的闪灭) 数据链路层协议定义了(通过通信介质互连的设备间的)数据传输规范 (常见的通信介质有同轴电缆.双绞线 ...
- DMZ是什么
刚刚接触安全域,实在是佩服自己真的是菜,,,啥都不懂,看看过段时间能有多大进步吧... 概念 DMZ:它是一个缓冲区,一个隔离区.它是位于两台防火墙之间的区域,相对于INTER网来说安全级别高一些,但 ...
- P5911 [POI2004]PRZ (状态压缩dp+枚举子集)
题目背景 一只队伍在爬山时碰到了雪崩,他们在逃跑时遇到了一座桥,他们要尽快的过桥. 题目描述 桥已经很旧了, 所以它不能承受太重的东西.任何时候队伍在桥上的人都不能超过一定的限制. 所以这只队伍过桥时 ...