asp.net-core - 使用 asp.net core 3.1 + linux nginx 找不到资源(静态文件问题?)
问题描述
我正在尝试在我的树莓派 4 上运行应用程序 asp.net core 3.1 MVC。该应用程序及其资源文件(img、css ...)在 IIS 调试模式(Windows)下运行良好。
我按照本教程设置了 linux 环境:tuto 该应用程序在 linux 中启动良好,但页面上没有资源。
所以我检查了关于静态文件的微软文档页面:静态文件 和其他教程。大多数情况下,他们解释了如何更改资源目录路径,但这不是我的问题。我只是想先看看它与 wwwroot 一起使用。
如您所见,我没有更改 startup.cs 中的任何内容:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
}
}
在 program.cs 中都没有:
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
nginx配置文件内容:
server {
listen 80 default_server;
server_name _;
location / {
proxy_pass http://localhost:5000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection keep-alive;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
请问您有什么想法,如何解决?感谢您阅读本文:)
解决方案
问题已解决:静态文件应位于 /home/user 而不是我设置应用程序的位置
推荐阅读
- ruby - 如何将 SASS/Compass 放入 DDEV Web 容器?
- json - 为什么 bash 不使用 jq -r bash IFS 显式定义变量来拆分数组
- generics - 如何使用 Class 类型的参数调用方法
在科特林? - azure-functions - Azure QnA maker 无法通过引发 ExtractionFailure 错误代码来创建知识库
- node.js - 如果我已经可以使用 db.query 为什么我需要 app.CRUD
- c++ - 比较两个 C++ 容器时 > 运算符有什么作用?
- twitter-bootstrap-3 - Vuetify 和 Bootstrap 网格冲突仅在本地
- javascript - 来自同步函数的异步函数调用 (Node.js)
- python - 在 Heroku 上使用 Scrapy Selenium 中间件
- php - 如何使用 php 解码 Json 并接收服务器请求