繁体   English   中英

如何在 Ubuntu 上使用 NginX 为 Blazor 应用程序提供服务

[英]How to serve a Blazor app using NginX on Ubuntu

我正在尝试将默认的 Blazor hello world 应用程序(https://dotnet.microsoft.com/learn/aspnet/blazor-tutorial/intro )提供给公共互联网。 我试图通过在 Ubuntu 20.04 LTS 安装上运行 NginX 来实现这一点。

我使用命令“dotnet run”运行 hello world 应用程序。 这使得应用程序在 localhost:5000 可用。 I then use NginX to pass any requests to the servers public ip to localhost 5000. Instead of loading all files, I only get the raw html file, without any of the.css or.js files required.

图片:Html 页面未加载 css 或 js 文件

因此,当通过 localhost:5000 查看应用程序时,我得到了工作页面。 通过服务器公共 IP 查看它时,我只得到原始 html,没有 js 或 css 文件。 例如,当通过 localhost:5000/counter 查看应用程序时,会加载计数器页面。 当使用 IP/计数器通过公共互联网访问它时,什么都没有加载。

这是我在 etc/nginx/sites-available/default 下的 nginx 配置。 不确定我需要更改什么或在哪里可以找到有关此的更多信息。

 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; }

这就是我在我的临时测试平台(Raspbian)上使用的。 它对我有用,但我不保证从安全角度来看它是正确的,请在部署之前进行自己的审查。

server {
    listen 80;
    server_name xxxxx.duckdns.org;
    return 301 https://$host$request_uri;
}

server
{
    listen              443 ssl;
    server_name         xxxxx.duckdns.org;
    keepalive_timeout   70;

    ssl_certificate     /path/to/certs/xxxxx.duckdns.org/cert.pem;
    ssl_certificate_key /path/to/certs/xxxxx.duckdns.org/privkey.pem;
    ssl_protocols       TLSv1 TLSv1.1 TLSv1.2;
    ssl_ciphers         HIGH:!aNULL:!MD5;
    ssl_session_cache   shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_dhparam         /etc/nginx/ssl/dhparam.pem;
    add_header          Strict-Transport-Security "max-age=63072000; includeSubdomains";
    add_header          X-Frame-Options DENY;

    location /
    {
        proxy_pass http://localhost:5000;
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM