粽是好运 發表於 2024-11-5 11:46:24

如何使用linux+nginx 作为unity webgl的服务器

<div id="navCategory"><h5 class="catalogue">目录</h5><ul class="first_class_ul"><li><a href="#_label0">使用linux+nginx 作为unity webgl的服务器</a></li><ul class="second_class_ul"><li><a href="#_lab2_0_0">下载nginx 使用图形界面</a></li><li><a href="#_lab2_0_1">下载ngixn使用命令行</a></li><li><a href="#_lab2_0_2">命令行</a></li></ul><li><a href="#_label1">配置nginx</a></li><ul class="second_class_ul"></ul><li><a href="#_label2">启动nginx</a></li><ul class="second_class_ul"></ul></ul></div><p class="maodian"><a name="_label0"></a></p><h2>使用linux+nginx 作为unity webgl的服务器</h2>
<p>建议使用命令行下载,使用源码编译可能编译不过。</p>
<p>自己创建一个uinty webgl项目,或者下载我上传的unity webgl项目</p>
<p><a href="https://download.csdn.net/download/GoodCooking/24339451" target="_blank">点击下载</a></p>
<p class="maodian"><a name="_lab2_0_0"></a></p><h3>下载nginx 使用图形界面</h3>
<p>下载nginx 或者使用命令行下载nginx<br />下载,这是用于Linux的。</p>
<p>https://nginx.org/en/download.html</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202411/2024110511275519.png" /></p>
<p>解压</p>
<div class="jb51code"><pre class="brush:bash;"> tar -xvf nginx-1.26.2.tar.gz </pre></div>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202411/2024110511275620.png" /></p>
<p>拷贝文件</p>
<div class="jb51code"><pre class="brush:bash;">//创建一个路径在/etc/nginx/nginx_20241030
sudo mkdir -p /etc/nginx/nginx_20241030
//拷贝解压文件到上面创建的路径
sudo cp -r nginx-1.26.2 /etc/nginx/nginx_20241030/
//看看文件在不在
ls /etc/nginx/nginx_20241030/</pre></div>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202411/2024110511275621.png" /></p>
<p class="maodian"><a name="_lab2_0_1"></a></p><h3>下载ngixn使用命令行</h3>
<p><a href="https://www.jb51.net/server/330080w60.htm" rel="nofollow" target="_blank">https://www.jb51.net/server/330080w60.htm</a></p>
<p>将unity webgl 文件拷贝到linux 图形界面和windows操作一样</p>
<p>解压zip的命令</p>
<p class="maodian"><a name="_lab2_0_2"></a></p><h3>命令行</h3>
<p>将文件拷贝到u盘中,将U盘插入到linux机器上</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202411/2024110511275622.png" /></p>
<div class="jb51code"><pre class="brush:bash;">//找到u盘
raspberry@raspberrypi:~ $ lsblk
NAME      MAJ:MIN RMSIZE RO TYPE MOUNTPOINT
sda         8:0    1 58.6G0 disk
└─sda1      8:1    1 58.6G0 part /media/raspberry/HIKSEMI
mmcblk0   179:0    0 29.7G0 disk
├─mmcblk0p1 179:1    0256M0 part /boot
└─mmcblk0p2 179:2    0 29.5G0 part /
//查看u盘文件
cd /media/raspberry/HIKSEMI/
ls
//复制文件到Downloads
sudo cp LOOKCubeA.zip/home/raspberry/Downloads
//解压文件
确认已经安装了unzip
unzip -v
安装会输出版本号,记得先运行 cd ~切换到home
么有安装就安装
sudo apt-get update
sudo apt-get install unzip
解压
cd /home/pi/Downloads/
unzip LOOKCubeA.zip
//将文件复制到nginx下
切换到文件夹内部
cd LOOKCubeA/
编译nginx ,么有报错就是编译好了
sudo ./configure
复制文件
sudo cp -r * /etc/nginx/nginx_20241030/nginx-1.26.2/html
切换到复制的文件夹
cd /etc/nginx/nginx_20241030/nginx-1.26.2/html
查看文件
ls
50x.html      Build/      index.html      TemplateData/
删除文件(如果有必要)
sudo rm -rf LOOKCubeA/</pre></div>
<p>最后的效果</p>
<p style="text-align:center"><img alt="" src="https://img.jbzj.com/file_images/article/202411/2024110511275623.png" /></p>
<p class="maodian"><a name="_label1"></a></p><h2>配置nginx</h2>
<p>nginx的配置文件Linux和Windows的差不多,需要改的有html文件的路径,在Linux中需要使用绝对路径</p>
<p>在windows中的路径配置,root是相对路径 root html;</p>
<div class="jb51code"><pre class="brush:plain;">         location / {
            root   html;
            indexindex.html index.htm;
            # 添加 CORS 头部
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
            # 处理 OPTIONS 请求
            if ($request_method = OPTIONS) {
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
                add_header Content-Length 0;
                add_header Content-Type text/plain;
                return 204;
            }
      }</pre></div>
<p>在linux中需要使用绝对路径 root /etc/nginx/html;</p>
<div class="jb51code"><pre class="brush:plain;">         location / {
            root   /etc/nginx/html;
            indexindex.html index.htm;
            # 添加 CORS 头部
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
            add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
            # 处理 OPTIONS 请求
            if ($request_method = OPTIONS) {
                add_header Access-Control-Allow-Origin *;
                add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
                add_header Access-Control-Allow-Headers 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization';
                add_header Content-Length 0;
                add_header Content-Type text/plain;
                return 204;
            }
      }</pre></div>
<div class="jb51code"><pre class="brush:bash;">切换到配置文件夹
cd /etc/nginx/nginx_20241030/nginx-1.26.2/conf
备份配置文件
sudo cp nginx.conf nginx.conf-save
编辑(如果会用nano)
sudo nano nginx.conf
不会用nano
复制复制一个到到桌面,使用文本编辑器编辑,编辑好之后再覆盖回去
复制到桌面一份
sudo cp nginx.conf/home/raspberry/Desktop
再复制回去
sudo cp /home/raspberry/Desktop/nginx.conf   /etc/nginx/nginx_20241030/nginx-1.26.2/conf/nginx.conf</pre></div>
<p class="maodian"><a name="_label2"></a></p><h2>启动nginx</h2>
<p>方式1,使用命令行安装的 可以使用下面的命令</p>
<div class="jb51code"><pre class="brush:bash;">//启动
sudo systemctl start nginx
//重启
sudo systemctl restart nginx
//查看状态
sudo systemctl status nginx</pre></div>
<p>方式2,如果是自己编译的</p>
<p>我的没编译出来,架构不行,arm64,很奇怪。</p>
<p>到此这篇关于如何使用linux+nginx 作为unity webgl的服务器的文章就介绍到这了,更多相关linux nginx unity webgl服务器内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!</p>
頁: [1]
查看完整版本: 如何使用linux+nginx 作为unity webgl的服务器