我正在尝试将默认的Blazor Hello World应用程序(https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro)提供给公共互联网。我正在通过在Ubuntu 20.04 LTS安装中运行NginX来实现这一目标。
我使用命令“dotnet run”运行Hello World应用程序。这使得应用程序在localhost:5000可用。然后,我使用NginX将任何请求传递到服务器的公共IP地址到localhost 5000。但是,我只能获得原始的HTML文件,而没有任何所需的.css或.js文件。 图片:未加载CSS或JS文件的HTML页面 因此,当通过localhost:5000查看应用程序时,可以正常工作。但是,通过公共IP访问时,只显示原始的HTML文件,没有js或css文件。例如,通过localhost:5000/counter查看应用程序时,计数器页面会加载。但是,通过公共互联网使用IP/counter访问时,没有任何东西被加载。
这是我的nginx配置文件,在/etc/nginx/sites-available/default目录下。 我不确定需要更改什么或者在哪里可以找到更多关于此的信息。
我使用命令“dotnet run”运行Hello World应用程序。这使得应用程序在localhost:5000可用。然后,我使用NginX将任何请求传递到服务器的公共IP地址到localhost 5000。但是,我只能获得原始的HTML文件,而没有任何所需的.css或.js文件。 图片:未加载CSS或JS文件的HTML页面 因此,当通过localhost:5000查看应用程序时,可以正常工作。但是,通过公共IP访问时,只显示原始的HTML文件,没有js或css文件。例如,通过localhost:5000/counter查看应用程序时,计数器页面会加载。但是,通过公共互联网使用IP/counter访问时,没有任何东西被加载。
这是我的nginx配置文件,在/etc/nginx/sites-available/default目录下。 我不确定需要更改什么或者在哪里可以找到更多关于此的信息。
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;
server_name _;
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
proxy_pass http://localhost:5000/;
try_files $uri $uri/ /css /wwwroot /Shared /Services =404;
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;
}