部署nginx多站点游戏
一、Nginx 多游戏站点部署前置环境准备
1.安装vim命令
yum -y install vim2.CentOS系统需要关闭selinux
#关闭selinux [root@oldboy ~]# setenforce 0 [root@oldboy ~]# getenforce Permissive # 变为此单词成功 #永久关闭、禁止开机自启 [root@oldboy ~]# sed -i '7c SELINUX=disabled' /etc/selinux/config3.关闭firewalld防火墙
#立即停止当前正在运行的firewalld防火墙(临时关闭,重启服务器后防火墙会自动恢复开启) [root@oldboy ~]# systemctl stop firewalld #取消开机自启firewalld防火墙 [root@oldboy ~]# systemctl disable firewalld 或 #立刻关闭防火墙 + 永久取消开机自启,一条命令完成上面两条的效果 [root@oldboy ~]# systemctl disable --now firewalld4.配置epel仓库
[root@oldboy ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo5.安装wget命令
[root@oldboy ~]# yum -y install wget6.安装nginx服务(做网站的服务)
[root@oldboy ~]# yum -y install nginx7.第三步: 启动nginx服务
# 立即启动nginx服务 [root@oldboy ~]# systemctl start nginx # 设置开机自启 [root@oldboy ~]# systemctl enable nginx\ 或 #一条命令同时「启动 + 开机自启」 [root@oldboy ~]#systemctl enable --now nginx二、搭建植物大战僵尸
1.进入到nginx/conf.d配置文件目录
#进入到nginx/conf.d配置文件目录 [root@oldboy ~]# cd /etc/nginx/conf.d [root@oldboy /etc/nginx/conf.d]# ll total 02.创建植物大战僵尸专属 Nginx 配置文件 zwdzjs.conf
[root@oldboy /etc/nginx/conf.d]# vim zwdzjs.conf #将一下配置文件写进去 server { listen 80; #监听端口,当前网站使用80端口(http默认端口) server_name www.zwdzjs.com; #绑定访问域名,访问 www.zwdzjs.com 才会匹配这个站点 location / { # location / 匹配所有访问路径,/ 代表根路径,所有请求都会进入这里 root /code/zwdzjs; # root:网站代码根目录,浏览器访问时去服务器 /code/zwdzjs 文件夹找文件 index index.html; # index:默认首页文件,访问域名不写文件名时,自动打开 index.html } }3.检查配置
[root@oldboy /etc/nginx/conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful4.重启nginx生效
[root@oldboy /etc/nginx/conf.d]# systemctl restart nginx5.创建一个/code/zwdjs目录来存放植物大战僵尸的压缩包
#创建一个/code/zwdzjs目录来存放植物大战僵尸的压缩包 [root@oldboy ~]# mkdir -p /code/zwdzjs #切换到/code/zwdzjs目录下 [root@oldboy ~]# cd /code/zwdzjs #检查一下当时所在路径 [root@oldboy /code/zwdzjs]pwd /code/zwdzjs6.上传并解压代码
#1.将植物大战僵尸的压缩包拖拽到/code/zwdzjs目录下 #2.解压植物.zip [root@oldboy /code/zwdzjs]unzip 植物.zip #3.解压后检查当前目录文件 [root@oldboy /code/zwdzjs]# ll 总用量 196012 drwxr-xr-x 2 root root 72 8月 26 2022 预览图 drwxr-xr-x 2 root root 4096 8月 26 2022 audio -rw-r--r-- 1 root root 8603 8月 26 2022 favicon.ico drwxr-xr-x 6 root root 64 8月 26 2022 images -rw-r--r-- 1 root root 165 8月 26 2022 'index (2).html' -rw-r--r-- 1 root root 23989 8月 26 2022 index.html drwxr-xr-x 2 root root 227 8月 26 2022 js drwxr-xr-x 2 root root 8192 8月 26 2022 level -rw-r--r-- 1 root root 200616163 7月 1 15:02 NewPvzJs-v1.6-master.zip -rw-r--r-- 1 root root 773 8月 26 2022 README.md -rw-r--r-- 1 root root 4598 8月 26 2022 U.htm -rw-r--r-- 1 root root 28536 8月 26 2022 UI.css7..windows做本地hosts劫持,将访问www.zwdzjs.com的用户劫持到10.0.0.107(分为6步)
1. hosts文件存放在windown中的C:\Windows\System32\drivers\etc目录下
2.将hosts文件拖拽到桌面上
3.桌面创建txt文件
4.打开txt文件
5.将hosts拖拽到txt文件中进行修改(在文件最后一行添加)
6.修改完成后按"ctrl+s“保存即可,然后拖回到 C:\Windows\System32\drivers\etc目录下
8. 浏览器访问www.zwdzjs.com
9.如果打不开的话就重新执行第3、4步骤重启一下nginx
三、搭建小霸王(和搭建植物大战僵尸意思,只不过配置文件存放路径不同)
1.进入到nginx/conf.d配置文件目录
#进入到nginx/conf.d配置文件目录 [root@oldboy ~]# cd /etc/nginx/conf.d [root@oldboy /etc/nginx/conf.d]# ll total 02.创建植物大战僵尸专属 Nginx 配置文件 xbw.conf
[root@oldboy /etc/nginx/conf.d]# vim xbw.conf #将一下配置文件写进去 server { listen 80; #监听端口,当前网站使用80端口(http默认端口) server_name www.xbw.com; #绑定访问域名,访问 www.xbw.com 才会匹配这个站点 location / { # location / 匹配所有访问路径,/ 代表根路径,所有请求都会进入这里 root /code/xbw; # root:网站代码根目录,浏览器访问时去服务器 /code/xbw 文件夹找文件 index index.html; # index:默认首页文件,访问域名不写文件名时,自动打开 index.html } }3.检查配置
[root@oldboy /etc/nginx/conf.d]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful4.重启nginx生效
[root@oldboy /etc/nginx/conf.d]# systemctl restart nginx5.创建一个/code/xbw目录来存放植物大战僵尸的压缩包
#创建一个/code/zwdjs目录来存放植物大战僵尸的压缩包 [root@oldboy ~]# mkdir -p /code/xbw #切换到/code/xbw目录下 [root@oldboy ~]# cd /code/xbw #检查一下当时所在路径 [root@oldboy /code/xbw]pwd /code/xbw6.上传并解压代码
#1.将植物大战僵尸的压缩包拖拽到/code/xbw目录下 #2.解压FC小霸王怀旧游戏机-HTML源码.zip [root@oldboy /code/xbw]unzip FC小霸王怀旧游戏机-HTML源码.zip #3.解压后检查当前目录文件 [root@oldboy /code/xbw]# ll 总用量 7768 -rw-r--r-- 1 root root 28032 5月 24 2021 bgm.mp3 drwxr-xr-x 2 root root 23 5月 24 2021 css -rw-r--r-- 1 root root 7902976 6月 29 10:53 FC小霸王怀旧游戏机-HTML源码.zip drwxr-xr-x 2 root root 23 5月 24 2021 images -rw-r--r-- 1 root root 8956 5月 24 2021 index.html drwxr-xr-x 2 root root 213 5月 24 2021 js drwxr-xr-x 2 root root 4096 5月 24 2021 roms -rw-r--r-- 1 root root 811 5月 24 2021 shuoming.html7..windows做本地hosts劫持,将访问www.xbw.com的用户劫持到10.0.0.107(分为6步)
1. hosts文件存放在windown中的C:\Windows\System32\drivers\etc目录下
2.将hosts文件拖拽到桌面上
3.桌面创建txt文件
4.打开txt文件
5.将hosts拖拽到txt文件中进行修改(在文件最后一行添加)
6.修改完成后按"ctrl+s“保存即可,然后拖回到 C:\Windows\System32\drivers\etc目录下
8. 浏览器访问www.xbw.com
三、最后一步: 战斗吧少年