马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
x
1.简朴先容
Blazor应用可以摆设到Internet Information Servers(简称IIS),也可以摆设到nginx中。也可以以docker容器的情势来摆设的或者摆设到Cloud中(好比azure web app等)
这边尝试一下在nginx中摆设一下Blazor Web Assembly Standalone app
2.详细说明
2.1 创建项目
在Visual Studio 2022中,以Blazor Web Assembly Standalone app为模板创建项目
2.2 发布项目
可以在Visual Studio 2022中举行发布,可以利用命令的方式来发布
2.2.1 VisualStudio发布
1) 右键点击项目,选择菜单项Publish
2) 点击Folder
3) 设定 Folder location,然后点击Publish举行发布
4) 发布结果如下图,
2.2.2 命令行发布
dotnet publish -c Release -o "blazorwasmartificats"
发布文件夹中的内容如下,
wwwroot文件夹下面的内容如下,
notes: .NET9中 对于静态的文件内容做了压缩(好比html, css, javascript),这样淘汰了网站访问时候所用的时间(文件更小)
2.3 设置nginx
修改一下nginx中的设置文件 nginx.conf
- server {
- listen 7527;
- server_name localhost;
- location /{
- root D:\blazorwasmartificats\wwwroot;
- index index.html index.htm;
- try_files $uri $uri/ /index.html;
- location /myblazorapp/_framework/ {
- gzip_static on;
- }
- }
-
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
复制代码 紧张是设定一下nginx.conf设置文件中的 server_name, location, root以及其index
2.4 运行一下
在命令行中,输入start nginx.exe
如果nginx启动乐成,则可以看到两个和nginx相关的进程,一个是工作进程,一个是主进程
可以利用Powershell命令检察一下 get-process | ?{$_.ProcessName -like '*nginx*'}
在命令行中,输入nginx -t,检测一下设置文件是否能正常运作
在欣赏器中,打开网页http://localhost:7527,发现页面最后可以正常显示出来
note, 可以在nginx中进一步设置MIME types,certificats等
3.总结
本文简朴记载了一下在nginx中摆设Blazor Web Assembly Standalone app的操纵过程。
如果哪里有错误的地方,贫困告之,谢谢谢谢!
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |