一、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. NSThread线程对象

    NSThread 创建线程的方式 准备在后台线程调用的方法 longOperation: - (void)longOperation:(id)obj { NSLog(@"%@ - %@&qu ...

  2. [LeetCode]78. 子集(位运算;回溯法待做)

    题目 给定一组不含重复元素的整数数组 nums,返回该数组所有可能的子集(幂集). 说明:解集不能包含重复的子集. 示例: 输入: nums = [1,2,3] 输出: [ [3],   [1],   ...

  3. [补题]求a[i]+a[j]+i-j的最大值,要求i<j

    题目 如题. 例: 输入: 5 11 6 5 18 12 输出: 29 题解 思路: 一直是按着(a[i]+a[j])+(i-j)想后序的思路,不应该限制住自己,应该多考虑拆的方法.正确思路是把a[i ...

  4. [Binder深入学习二]Binder驱动——基础数据结构二

    Userspace和KernelSpace进行交互时,大部分命令是通过 ioctl 实现的,在这个过程中,最重要的一个便是 BINDER_WRITE_READ 命令了. #define BINDER_ ...

  5. mariadb 3

    MariaDB第三章(select)   基本查询 --查询基本使用(条件,排序,聚合函数,分组,分页) --创建学生表 create table students ( id int unsigned ...

  6. 绝了!一个妹子 rm -rf 把公司整个数据库删没了...

    经历了两天不懈努力,终于恢复了一次误操作删除的生产服务器数据.对本次事故过程和解决办法记录在此,警醒自己,也提示别人莫犯此错.也希望遇到问题的朋友能找到一丝灵感解决问题. 01 事故背景 安排一个妹子 ...

  7. java代码复用(继承,组合以及代理)

    作为一门面向对象开发的语言,代码复用是java引人注意的功能之一.java代码的复用有继承,组合以及代理三种具体的表现形式,下面一一道来. 第一种方式是通过按照现有的类的类型创建新类的方式实现代码的复 ...

  8. HTML自学第一篇

    教程来自W3CSchool 因为笔者有过开发经验 本篇只是个人对HTML自学的笔记,可能不适合用于给他人理解和学习 什么是 HTML HTML 指的是超文本标记语言 (Hyper Text Marku ...

  9. BTRsys1~2系列靶机渗透

    BTRsys系列靶机渗透 BTRsys1 端口发现加目录扫描. 发现目录:http://192.168.114.161/login.php 尝试弱密码失败,查看源代码. <script type ...

  10. python-生成器(generation)

    阐述思路是:迭代(iteration).迭代器(iterator).生成器(generator). 迭代 迭代是重复反馈过程的活动,其目的通常是为了接近并到达所需的目标或结果.每一次对过程的重复被称为 ...