一、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基础之搭建小游戏的更多相关文章

  1. Nginx基础环境搭建

    1.下载docker toolbox https://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/ 2.选择好安装目录 一路nex ...

  2. Vue.js-09:第九章 - 组件基础再探(data、props)

    一.前言 在上一章的学习中,我们学习了 Vue 中组件的基础知识,知道了什么是组件,以及如何创建一个全局/局部组件.不知道你是否记得,在上一章中,我们提到组件是一个可以复用的 Vue 实例,它与 Vu ...

  3. 青瓷qici - H5小游戏 抽奖机 “one-arm bandit”

    写在前面 本文实现一个简单的抽奖效果,使用青瓷qici引擎,其中应用了Tween动画,粒子系统,遮罩,UI界面布局,项目设置,发布等功能呢. 目前开发采用1.0.7版本,后续如果界面有所变化请参考这个 ...

  4. Objective-C 基础教程第九章,内存管理

    目录 Object-C 基础教程第九章,内存管理 前言: 对象生命周期 引用计数 RetainCount1项目例子 对象所有权 访问方法中的保留和释放 自动释放 所有对象放入池中 自动释放池的销毁时间 ...

  5. 通过游戏学python 3.6 第一季 第九章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁定账号--锁定次数--菜单功能'menufile

      通过游戏学python 3.6 第一季 第九章 实例项目 猜数字游戏--核心代码--猜测次数--随机函数和屏蔽错误代码--优化代码及注释--简单账号密码登陆--账号的注册查询和密码的找回修改--锁 ...

  6. 看一眼就学会的 HTML 小游戏搭建!

    本文作者:CODING 用户 - xfly 身边经常会有小伙伴问我有没有办法不买服务器也能上线自己的个人项目,比如不少同学都非常喜欢搭建一个属于自己的博客站点或者小游戏等. 目前相对比较简便的且不花自 ...

  7. <自动化测试方案_9>第九章、持续集成平台搭建

    第九章.持续集成平台搭建 (一)什么是持续集成 参考文章地址:https://blog.csdn.net/qq_32261399/article/details/76651376 敏捷软件开发(英语: ...

  8. iOS 基础入门--Bull' Eye 小游戏 

      说明   Bull's Eye小游戏是http://www.raywenderlich.com/store/ios-apprentice里非常酷的入门demo 跟着该教程一步步做下来便有了 ...

  9. Wordpress搭建社交型小游戏网站10大步骤

    http://www.aliyun.com/zixun/content/2_8_196141.html ———————————————————————————————————————————————— ...

随机推荐

  1. unittest上下关联关系的接口——继承测试用例类

    如果有上下关联,可以用到一个类继承测试用例类(里面的测试用例函数名不要带test)的方法去调用用例, 注意:如果放到同一个类会出现用例重复执行的情况 ,如果测试用例的函数带了test,一旦被调用,会被 ...

  2. ⏰ Moment.js 宣布停止开发,现在该用什么?

    本文整理自 Monent.js 官方英文公告 https://momentjs.com/docs/#/-project-status/ Moment.js 宣布停止开发,进入维护状态. 这是一个大而全 ...

  3. vue-router-next 通过hash模式访问页面不生效,直接刷新页面一直停留在根路由界面的解决办法

    vue3中,配合的vueRouter版本更改为vue-router-next通过 npm i vue-router@next 的方式进行引入添加,随后创建 router.js,在main.js里面引入 ...

  4. React使用AntV G6实现流程图

    安装 npm install @antv/g6 --save 引用 import G6 from '@antv/g6' 自定义节点 /** * 方式一 */ G6.registerNode('rect ...

  5. python的快捷键

    常用快捷键 1.Ctrl + Enter:在下方新建行但不移动光标 2.Shift + Enter:在下方新建行并移到新行行首 3.Ctrl + /:注释(取消注释)选择的行 4.Ctrl + Alt ...

  6. Linux MMC 驱动子系统简述(源码剖析)

    1. Linux MMC 驱动子系统 块设备是Linux系统中的基础外设之一,而 MMC/SD 存储设备是一种典型的块设备.Linux内核设计了 MMC子系统,用于管理 MMC/SD 设备. MMC ...

  7. python3 结束进程

    为什么会去结束进程呢?因为在做appium中遇到H5跳转了多个页面的时候,出现了获取的pagesource是上一个页面的情况,这时候就需要先退出webview,然后杀掉chromedriver的进程, ...

  8. linux系统或centos7安装nginx

    一.Linux下安装nginx 1.添加源 sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-cen ...

  9. 【字符串算法】字典树(Trie树)

    什么是字典树 基本概念 字典树,又称为单词查找树或Tire树,是一种树形结构,它是一种哈希树的变种,用于存储字符串及其相关信息. 基本性质 1.根节点不包含字符,除根节点外的每一个子节点都包含一个字符 ...

  10. 使用Cadence绘制PCB流程

    转载:https://blog.csdn.net/hailin0716/article/details/47169799 之前使用过cadence画过几块板子,一直没有做过整理.每次画图遇到问题时,都 ...