Nginx搭建游戏
目录
一:Nginx搭建《小游戏》
1.上传《象棋游戏》代码
2.编辑配置文件(尾部必须要加 .conf<文件>)
[root@web01 conf.d]# vim /etc/nginx/conf.d/game.conf
server {
listen 80;
#server_name localhost;
server_name www.game.com;
location / {
root /opt/jiaoben1765/jiaoben1765;
index index.html;
}
}
3、测试配置文件是否正常
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful
4、重启Nginx
[root@web01 conf.d]# systemctl restart nginx
5、域名解析
1.windows目录下域名解析DNS
C:\Windows\System32\drivers\etc\hosts
2.文件内输入 ip地址 域名
172.16.1.7 www.game.com
6.测试域名访问
二:Nginx多次搭建《马里奥游戏》
1.切换路径到配置路径
cd /etc/nginx/conf.d
2.复制相同配置文件
[root@web01 conf.d]# cp game.confcd game1.confcd
3.编辑配置文件(尾部必须要.conf《文件》
[root@web01 conf.d]# vim game1.conf
server {
listen 80;
server_name www1.game.com;
location / {
root /opt/Mario;
index index.html;
}
}
3、测试配置文件是否正常
[root@web01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
4、重启Nginx
[root@web01 conf.d]# systemctl restart nginx
5、域名解析
1.windows目录下域名解析DNS
C:\Windows\System32\drivers\etc\hosts
2.文件内输入 ip地址 域名
172.16.1.7 www.game.com www1.game.com