【问题标题】:How to serve a Blazor app using NginX on Ubuntu如何在 Ubuntu 上使用 NginX 提供 Blazor 应用程序
【发布时间】:2021-04-11 14:30:53
【问题描述】:

我正在尝试提供默认的 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 文件。

Image: Html page without css or js files loaded

因此,当通过 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;
        }

【问题讨论】:

    标签: c# .net ubuntu nginx blazor


    【解决方案1】:

    这是我在我的临时测试平台 (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;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-05
      • 1970-01-01
      • 2021-12-14
      • 2018-05-15
      • 1970-01-01
      • 2015-09-18
      • 1970-01-01
      相关资源
      最近更新 更多