部署nginx多站点游戏
一、Nginx 多游戏站点部署前置环境准备1.安装vim命令yum -y install vim2.CentOS系统需要关闭selinux#关闭selinux [rootoldboy ~]# setenforce 0 [rootoldboy ~]# getenforce Permissive # 变为此单词成功 #永久关闭、禁止开机自启 [rootoldboy ~]# sed -i 7c SELINUXdisabled /etc/selinux/config3.关闭firewalld防火墙#立即停止当前正在运行的firewalld防火墙临时关闭重启服务器后防火墙会自动恢复开启 [rootoldboy ~]# systemctl stop firewalld #取消开机自启firewalld防火墙 [rootoldboy ~]# systemctl disable firewalld 或 #立刻关闭防火墙 永久取消开机自启一条命令完成上面两条的效果 [rootoldboy ~]# systemctl disable --now firewalld4.配置epel仓库[rootoldboy ~]# wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo5.安装wget命令[rootoldboy ~]# yum -y install wget6.安装nginx服务(做网站的服务[rootoldboy ~]# yum -y install nginx7.第三步: 启动nginx服务# 立即启动nginx服务 [rootoldboy ~]# systemctl start nginx # 设置开机自启 [rootoldboy ~]# systemctl enable nginx\ 或 #一条命令同时「启动 开机自启」 [rootoldboy ~]#systemctl enable --now nginx二、搭建植物大战僵尸1.进入到nginx/conf.d配置文件目录#进入到nginx/conf.d配置文件目录 [rootoldboy ~]# cd /etc/nginx/conf.d [rootoldboy /etc/nginx/conf.d]# ll total 02.创建植物大战僵尸专属 Nginx 配置文件 zwdzjs.conf[rootoldboy /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.检查配置[rootoldboy /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生效[rootoldboy /etc/nginx/conf.d]# systemctl restart nginx5.创建一个/code/zwdjs目录来存放植物大战僵尸的压缩包#创建一个/code/zwdzjs目录来存放植物大战僵尸的压缩包 [rootoldboy ~]# mkdir -p /code/zwdzjs #切换到/code/zwdzjs目录下 [rootoldboy ~]# cd /code/zwdzjs #检查一下当时所在路径 [rootoldboy /code/zwdzjs]pwd /code/zwdzjs6.上传并解压代码#1.将植物大战僵尸的压缩包拖拽到/code/zwdzjs目录下 #2.解压植物.zip [rootoldboy /code/zwdzjs]unzip 植物.zip #3.解压后检查当前目录文件 [rootoldboy /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.修改完成后按ctrls“保存即可然后拖回到 C:\Windows\System32\drivers\etc目录下8. 浏览器访问www.zwdzjs.com9.如果打不开的话就重新执行第3、4步骤重启一下nginx三、搭建小霸王(和搭建植物大战僵尸意思只不过配置文件存放路径不同)1.进入到nginx/conf.d配置文件目录#进入到nginx/conf.d配置文件目录 [rootoldboy ~]# cd /etc/nginx/conf.d [rootoldboy /etc/nginx/conf.d]# ll total 02.创建植物大战僵尸专属 Nginx 配置文件 xbw.conf[rootoldboy /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.检查配置[rootoldboy /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生效[rootoldboy /etc/nginx/conf.d]# systemctl restart nginx5.创建一个/code/xbw目录来存放植物大战僵尸的压缩包#创建一个/code/zwdjs目录来存放植物大战僵尸的压缩包 [rootoldboy ~]# mkdir -p /code/xbw #切换到/code/xbw目录下 [rootoldboy ~]# cd /code/xbw #检查一下当时所在路径 [rootoldboy /code/xbw]pwd /code/xbw6.上传并解压代码#1.将植物大战僵尸的压缩包拖拽到/code/xbw目录下 #2.解压FC小霸王怀旧游戏机-HTML源码.zip [rootoldboy /code/xbw]unzip FC小霸王怀旧游戏机-HTML源码.zip #3.解压后检查当前目录文件 [rootoldboy /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.修改完成后按ctrls“保存即可然后拖回到 C:\Windows\System32\drivers\etc目录下8. 浏览器访问www.xbw.com三、最后一步: 战斗吧少年